Problems with SyntaxError construction

Tim Fox timvolpe at
Wed Feb 18 14:59:59 UTC 2015

Hi all,

I've started a new thread for this, so as not to clutter the previous 
thread on exceptions.

I've come across a possible issue with creating SyntaxError objects (and 
potentially other exceptions although I haven't tested them).

In the above gist I create a SyntaxError specifying message, fileName, 
and lineNumber.

However fileName and lineNumber appear to be ignored, and instead the 
SyntaxError fileName and lineNumber are set to the fileName of the file 
where it was created and the lineNumber of the creation.

I'm not sure if I'm doing something wrong, but according to 
I should be able to create SyntaxError objects like this.

There appears to be a further issue. If I then throw the syntax error 
from the JS script, and catch it in Java like this:

try {
     } catch (ScriptException e) {
       System.out.println("message:" + e.getMessage());
       System.out.println("fileName:" + e.getFileName());
       System.out.println("lineNumber:" + e.getLineNumber());

Then the message, fileName and lineNumber always correspond to place 
where the object was created, not to the subsequently set values.

In other words, I can't figure out a way of creating a SyntaxError 
object in JS with my own values of fileName and lineNumber and have 
those values available in Java when caught.

Any ideas from the experts? :)

More information about the nashorn-dev mailing list