异常与错误


【Exceptions vs. errors】

JavaScript 异常是由于无效操作或作为 throw 语句目标而抛出的值。虽然这些值不要求必须是 Error 的实例或继承自 Error 的类,但 Node.js 或 JavaScript 运行时抛出的所有异常 都会Error 的实例。

【A JavaScript exception is a value that is thrown as a result of an invalid operation or as the target of a throw statement. While it is not required that these values are instances of Error or classes which inherit from Error, all exceptions thrown by Node.js or the JavaScript runtime will be instances of Error.】

有些异常在 JavaScript 层是不可恢复的。这类异常将始终导致 Node.js 进程崩溃。示例包括 C++ 层的 assert() 检查或 abort() 调用。

【Some exceptions are unrecoverable at the JavaScript layer. Such exceptions will always cause the Node.js process to crash. Examples include assert() checks or abort() calls in the C++ layer.】