类:SyntaxError


【Class: SyntaxError

表示程序不是有效的 JavaScript。这些错误可能仅作为代码评估的结果被产生和传播。代码评估可能由于使用 evalFunctionrequire虚拟机 而发生。这些错误几乎总是表明程序出现了问题。

【Indicates that a program is not valid JavaScript. These errors may only be generated and propagated as a result of code evaluation. Code evaluation may happen as a result of eval, Function, require, or vm. These errors are almost always indicative of a broken program.】

try {
  require('node:vm').runInThisContext('binary ! isNotOk');
} catch (err) {
  // 'err' will be a SyntaxError.
} 

SyntaxError 实例在创建它们的上下文中是无法恢复的——它们只能被其他上下文捕获。