"e" will not be a Java exception, even if you threw a Java exception.  
However, Rhino has a non-ECMA extension to the error object in this  
case on the error object - a property named "javaException".  
Therefore, "e.javaException" gives you access to the underlying Java  
exception.

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
On 2008.01.30., at 4:37, Amit wrote:

> I am interfacing to some Java code using Javascript. Is it possible to
> print just the javascript stack trace if an exception occurs?
>
> 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




_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to