Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created February 18, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/f99ad4c78d246d2d6aee to your computer and use it in GitHub Desktop.
Save purplefox/f99ad4c78d246d2d6aee to your computer and use it in GitHub Desktop.
var STDOUT = java.lang.System.out;
STDOUT.println("starting test");
var body =
"function() {\n" +
"// deliberate syntax error\n" +
"v a r num = 234;\n" +
"}\n//@ sourceURL=wibble.js";
STDOUT.println("module source is:\n" + body);
try {
eval(body);
} catch (ex) {
if (ex instanceof SyntaxError) {
STDOUT.println("message is:" + ex.message);
STDOUT.println("line no is:" + ex.lineNumber);
STDOUT.println("filename is:" + ex.fileName);
STDOUT.println("stack is:\n" + ex.stack);
var correctException = ex.nashornException.cause;
STDOUT.println("ne message is:" + correctException.message);
STDOUT.println("ne line no is:" + correctException.lineNumber);
STDOUT.println("ne filename is:" + correctException.fileName);
STDOUT.println("ne stack is:\n" + correctException.stack);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment