简体   繁体   中英

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>");

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM