Subj : Re: Rhino: Accessing embedded exception in JavaException To : Lewis Gardner From : Igor Bukanov Date : Wed Apr 21 2004 09:38 am Lewis Gardner wrote: > Unfortunately your solution does not seem to work for me. I did not realize that you needed to catch exception in JavaScript, not Java! In JavaScript the exception object representing exceptions thrown from Java methods contains javaException property which represents the original Java exception. For example, try { java.lang.Integer.parseInt(null); } catch (ex) { print(ex.javaException); } prints when executed in Rhino shell java.lang.NumberFormatException: null See also http://grazia.helma.at/pipermail/helma-dev/2004-March/000974.html which gives an example ho to use javaException and other properties of the exception object. Regards, Igor > This is the output: > > try { > callJavaFunctionThrowingFooException(); > } catch (ex) { > print(ex); // prints: JavaException: FooException: > print(ex.getWrappedException()); // undefined error > } > > If I analyse the exception class further it seems to be of the type > org.mozilla.javascript.NativeError. > > Where am I going wrong? BTW, FooException is a RuntimeException, could > that be the reason? If yes, is there any way I can still get at the > original exception? > > thanks, > Lewis > > Igor Bukanov wrote in message news:<4084EEC6.6000206@fastmail.fm>... > >>Lewis Gardner wrote: >> >>>Hi, >>>when I call a Java method via LiveConnect (Rhino) and the method >>>throws an exception the type of the exception thrown in >>>"JavaException". Is there any way I can access the original exception, >>>the one actually thrown by the Java method? >> >>I would suggest to upgrade to Rhino 1.5R5 which consistently rethrows >>exceptions from Java methods as org.mozilla.javascript.WrappedException >>where the method getWrappedException() returns the original exception >>object. >> >>Prior 1.5R5 Rhino could throw either >>org.mozilla.javascript.WrappedException or >>org.mozilla.javascript.JavaScriptException and in the later case to get >>the original object you have to call getValue() method there, check if >>it is an instance of Throwable and in addition if that was an instance >>of WrappedException, then call getWrappedException() to get the real >>exception source. >> >>In Rhino 1.5R5 JavaScriptException represents only exceptions thrown by >>scripts with JavaScript "throw" statement. >> >>Regards, Igor .