Rhino has poor support for Exceptions, they are not usable or useful, as in other scripts such as Groovy or JRuby.
To help you debug problems, I think you can use this trick. Rhino adds a non-standard property to the Error object, which you can access to print some error information.
try {
someCode()
}
catch(e) {
if(e.rhinoException != null)
{
e.rhinoException.printStackTrace();
}
}
Bindings, , - ?
, . , , JavaScriptException, , .
package test;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import sun.org.mozilla.javascript.*;
public class Main {
private static ScriptEngineManager mgr = new ScriptEngineManager();
private static ScriptEngine engine = mgr.getEngineByName("JavaScript");
public static void main(String... args) {
System.out.println("START");
try {
engine.eval("throw { error: \"cheese\", context: \"payload\" };");
} catch (ScriptException e) {
JavaScriptException jse = (JavaScriptException)e.getCause();
Object obj = jse.getValue();
ScriptableObject so = (ScriptableObject)obj;
System.out.println(so.get("error", so));
System.out.println(so.get("context", so));
}
System.out.println("END");
}
}