Hi all,
I am wondering how to get full "cause" history when rethrowing
exceptions. When I run the following script:
/*1*/ try {
/*2*/ try {
/*3*/ throw "errorString";
/*4*/ } catch ( e1 ) {
/*5*/ throw e1;
/*6*/ }
/*7*/ } catch (e2) {
/*8*/ throw e2;
/*9*/ }
My calling code ends up with "e2" which is a JavaScriptException. The
only line information I can seem to dig out of the JavaScriptException
is that the error occurred at line 8. I was expecting behavior closer
to Java which would attribute the error to line 3.
Here is some example code:
In Pure Java, the stack trace from t3.printStackTrace() says the error
orginated at the point of construction of the Throwable.
public void testNestedJavaCatches() {
try {
try {
try {
throw new Throwable("a Throwable");
}
catch ( Throwable t ) {
throw t;
}
} catch ( Throwable t2 ) {
throw t2;
}
} catch ( Throwable t3 ) {
t3.printStackTrace();
}
}
Whereas, this Java Code (which executes a JS text...)
public void testNestedCatches() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
try {
String scriptText = "/*1*/try{\n"+
"/*2*/ try{\n" +
"/*3*/ throw \"errorString\";\n" +
"/*4*/ } catch(e1) {\n" +
"/*5*/ throw e1;\n" +
"/*6*/ }\n" +
"/*7*/} catch (e2){ \n" +
"/*8*/ throw e2;\n" +
"/*9*/}";
ScriptableObject scriptable = new NativeObject();
cx.initStandardObjects(scriptable,true);
cx.evaluateString(scriptable, scriptText, "<debug>", 1,
null);
}
catch ( JavaScriptException t) {
System.out.println( t.details() );
t.printStackTrace();
System.out.println( t.getScriptStackTrace());
System.out.println( t.getValue() );
}
finally {
cx.exit();
}
}
Reports a Stack trace including "at script(<debug>:8)". It does not
mention the error ocurring at line 3 at all.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino