BlueDevilDan
Contributor
Contributor

Plugins and Java Methods that throw exceptions

Jump to solution

I am trying to determine how to deal in my plugin with exposing a java object method that could throw and exception. For the example below, I have added an object mapping for the exception class and the getErrno and getReason methods

in my java script I have

try {

method.invoke();

}

catch (e) {

errno = e.getErrno() ;

}

is the e that I catch going to be my java exception object or is it something else?

When I execute this (with invoke set to throw the exception) I get "TypeError: Cannot find function getErrno"

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

Basically, all exceptions are string message, not exceptions objects. What you can do is serialize the error and the message as the Exception string is the message of the excpeptions object.

View solution in original post

0 Kudos
3 Replies
BlueDevilDan
Contributor
Contributor

OK, I added a loop in my catch pull all the object attribute names of the exception. It appears that what comes up to the JavaScript is the rhinoException which occured because of the exception from my invoke method's exception. So do I have any way to access the exception thrown by my Java method, or do I need to provide another method of error out information out of my wrapped Java Method<code>?</code>

0 Kudos
admin
Immortal
Immortal

Basically, all exceptions are string message, not exceptions objects. What you can do is serialize the error and the message as the Exception string is the message of the excpeptions object.

0 Kudos
BlueDevilDan
Contributor
Contributor

Thanks for the reply. I was wanting to confirm what I was seeing since I didn't see any definitive information on this in the developer guide.

I only had one main facade class that I was exposing that threw method exceptions and those exceptions contained a couple custom values. What I did was created a decorator class to wrap it and had that decorator catch the exception and put those custom exception fields into attributes of the decorator class and exposed them to the Java Script layer. So my script basically needs to check for the error rather than catch the exception. That will work for my case.

0 Kudos