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).

https://gist.github.com/purplefox/dfe30a38098c1708e24b

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 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError 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 {
      engine.eval(script);
    } 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? :)


Reply via email to