cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

custom exception in thingworx

rgupta-21
1-Newbie

custom exception in thingworx

I have created a ConnectedThingClient in java. I am using invokeService() method to call services of a particular thing at Thingworx server.

Can I send a custom exception from Thingworx which could be caught at java client end?

e.g.

throw{

     "msg": <message>,

     "module": <module_name>,

     "projectVersion": <version>, ...

}

Requirement is this custom exception should be caught up at java client end, and I should be able to invoke methods as e.getMsg() or e.getModule() or e.getProjectVersion() considering e is the Exception object in catch.

But Thingworx raises error in script.

The workaround I am opting is-

I am creating the exception JSON with mentioned fields, converting this exception to a string and then throwing the string.

This way java client end calls e.getMessage() and then extracts the actual exception data from it.

So, I would like to know how can a custom exception be sent from Thingworx? And if not, is my workaround good or there can be a better solution to tackle this problem?

3 REPLIES 3
mhollenbach
5-Regular Member
(To:rgupta-21)

What error is ThingWorx raising from the script?

PaiChung
22-Sapphire I
(To:rgupta-21)

Don't think I quite understand what you are trying to do.

but every service on the client side can show the throw message by showing [server-message]

these will show up as an Alert drop down

Other ways to get custom messages to the client side would be to load them up in a Stream/Blog and display them in a mashup

Hi

Am I correct in thinking that you have a remote Thing that is attempting to trigger a service of a modelled Thing on the Platform?

If so, when you trigger that service it is being run inside the platform JVM, so you're not going to get exceptions coming back as part of the stack trace. You can get around this by setting up your platform service so that it returns an infotable containing any returned values from the service plus status information. Your code on the device then needs to parse the InfoTable to get either the success or failure messages and process accordingly.

Regards

Ian

Top Tags