Dave H
Dave H

Reputation: 547

How to access Java exception that causes ScriptException using JSR-223

I'm executing Javascripts using the JSR-223 script engine built into JRE6. The Javascripts are able to access Java code and objects. When an exception is thrown from the Java code that is executed from a JavaScript, the ScriptEngine will throw a ScriptException.

I want to be able to access the Java exception that caused the Javascript to throw an exception.

From the Javascript, I can catch the exception and look at the javaException field of the exception:

try
{
  .
}
catch (e)
{
  e.javaException.printStackTrace();
}

However, I don't have control of the Javascript, only the execution of them from the ScriptEngine. Is there a way to grab the "inner" Java exception from the ScriptException?

I believe if I was using Rhino, the RhinoException would have a Java exception available. The RhinoException is not available from the JSR-223 API.

Upvotes: 7

Views: 4217

Answers (1)

AlexR
AlexR

Reputation: 115378

have you tried e.getCause()?

Upvotes: 0

Related Questions