异常与错误


JavaScript 异常是一个作为一个无效操作的结果或作为一个 throw 声明的目标所抛出的值。 虽然它不要求这些值是 Error 的实例或继承自 Error 的类的实例,但所有通过 Node.js 或 JavaScript 运行时抛出的异常都是 Error 实例。

有些异常在 JavaScript 层是无法恢复的。 这些异常总会引起 Node.js 进程的崩溃。 例如 assert() 检测或在 C++ 层调用的 abort()

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.

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.