Can syntax errors be caught in JavaScript?

前端 未结 5 1248
说谎
说谎 2020-12-06 09:38

MDN states:

A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language wh

5条回答
  •  时光说笑
    2020-12-06 10:27

    You can catch programmer-generated and runtime exceptions but you cannot catch JavaScript syntax errors, though you may handle them in some browsers using window.onerror.

    This is taken from the book JavaScript- The Complete Reference by Thomas-Powell which I like very much. You can refer to the code examples in that book.

提交回复
热议问题