Catching JVM exceptions

A. Sundararajan sundararajan.athijegannathan at oracle.com
Wed Jan 1 20:48:26 PST 2014


Just adding to what Attila said:

For ECMAScript Error objects there is a property called 
"nashornException" that returns the underlying Java exception thrown.

try {
      func();
} catch (e) {
      print(e.nashornException);
}

Java exceptions are thrown "as is" (no wrapping of Java exceptions as 
ECMAScript objects)

-Sundar

On Monday 30 December 2013 04:07 PM, Attila Szegedi wrote:
> We don't wrap them initially, so "e" can be a java exception; catch(x if x instanceof java.io.FileNotFoundException) should work.
>
> On Dec 30, 2013, at 7:24 AM, Tal Liron <tal.liron at threecrickets.com> wrote:
>
>> How do you catch JVM exceptions in Nashorn? This is how it works in Rhino:
>>
>>             try {
>>                 ...
>>             }
>>             catch (x if x.javaException instanceof java.io.FileNotFoundException) {
>>             }



More information about the nashorn-dev mailing list