0

If a runtime error happens in script run by java's javascript engine, I can happily get the error and importantly the line number from the exception.

When loading a "level" I evaluate a level script to initialise things if needed, this also evaluates the functions that are optionally used by various events (if they are found)

However if there is for example a syntax error while evaluating (not running!) a function I get a message like this

[java] sun.org.mozilla.javascript.EvaluatorException: syntax error (<Unknown source>#1) in <Unknown source> at line number 1 at line 1,-1

even if the error is later in a function than its first line

how can I get the line and ideally the column number in the script where the error occurs?

1
  • it seems I can not catch a sun.org.mozilla.javascript.EvaluatorException nor cast a ScriptException to a sun.org.mozilla.javascript.EvaluatorException (if that helps!) Commented Oct 2, 2014 at 10:26

1 Answer 1

0

Owch!

seems my xml parser (sax) was stripping carriage returns (but is happy with other white space the tabs - go figure!)

my work around is to do...

os.write((" script=\""+levelScript.replace("\n","&#xA;\n")+"\"").getBytes());

for the script attribute (I add the \n after the xA entity just to make the xml more readable

anyhow if you haven't realised just yet... the script was loaded as all one long line so ALL errors ended up on line 1!!!

mind I could have sworn I was getting line numbers for run-time errors....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.