3 Replies Latest reply on Apr 6, 2016 6:40 AM by ianban RSS
    rgupta-2 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?

      • Re: custom exception in thingworx
        meghan Communicator

        What error is ThingWorx raising from the script?

        • Re: custom exception in thingworx
          pchung Collaborator

          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

          • Re: custom exception in thingworx
            ianban Creator

            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