My code looks like this:
try {
} catch (e) {
if (e instanceof java.lang.Exception)
e.printStackTrace();
}
'e.printStackTrace' calls the java.lang.Exception stack dump method.
In addition to this I would also like to display the javascript stack
dump when a Java exception is thrown. Is there a way to do it? Also is
there a way to print the combined Java and Javascript stack trace?
Regards
Amit
In compiled mode, you should see source names and line numbers in
script (as JS is compiled to a Java class with appropriate line number
information).
In interpreted mode, RhinoException and its subclasses will feature
script locations in the stack trace. If you let your exception
propagate out of the Script.exec() and catch it in Java and log it, it
will almost always be a RhinoException, so you get the script stack
trace.
There is another non-ECMA extension to the error object - a property
named "rhinoException". When an exception is thrown in Rhino, it is
usually wrapped into a WrappedException (which is a subclass of
RhinoException). Calling printStackTrace on it might be more useful.
So,
try
{
}
catch(e)
{
if(e.rhinoException != null)
{
e.rhinoException.printStackTrace();
}
else if(e.javaException != null)
{
e. javaException.printStackTrace();
}
}
should work from script and produce script stack locations in the trace.
Attila.
However, you won't see a RhinoException