DarkLightA
DarkLightA

Reputation: 15662

Why isn't JavaScript picking up on this error?

Rather than display the error details, the entire javascript is just not displayed. The subscripts and superscripts aren't displayed either!

try
{
document.write("<p>Fontsize: " + txt.fontsize(6px) + "</p>");
}
catch(err)
{
document.write("Error details: " + err);
}
document.write("<p>Subscript: " + txt.sub() + "</p>");
document.write("<p>Superscript: " + txt.sup() + "</p>");

Upvotes: 0

Views: 90

Answers (1)

SLaks
SLaks

Reputation: 887413

6px is invalid syntax.

Therefore, the entire script is not executed. (since it can't be parsed)

catch blocks catch runtime errors in your script.
If the script contains invalid syntax, the Javascript interpreter will throw out the entire script, because it makes no sense.
It will not try to recover whatever it can make sense out of.

Upvotes: 12

Related Questions