错误


¥Errors

在 Node.js 中运行的应用通常会遇到四类错误:

¥Applications running in Node.js will generally experience four categories of errors:

  • 标准的 JavaScript 错误,例如 <EvalError><SyntaxError><RangeError><ReferenceError><TypeError><URIError>

    ¥Standard JavaScript errors such as <EvalError>, <SyntaxError>, <RangeError>, <ReferenceError>, <TypeError>, and <URIError>.

  • 由底层操作系统约束触发的系统错误,例如尝试打开不存在的文件或尝试通过关闭的套接字发送数据。

    ¥System errors triggered by underlying operating system constraints such as attempting to open a file that does not exist or attempting to send data over a closed socket.

  • 由应用代码触发的用户指定的错误。

    ¥User-specified errors triggered by application code.

  • AssertionError 是一类特殊的错误,当 Node.js 检测到不应该发生的异常逻辑违规时会触发该错误。这些通常由 node:assert 模块引发。

    ¥AssertionErrors are a special class of error that can be triggered when Node.js detects an exceptional logic violation that should never occur. These are raised typically by the node:assert module.

Node.js 引发的所有 JavaScript 和系统错误都继承自标准 JavaScript <Error> 类,或者是标准 JavaScript <Error> 类的实例,并且保证至少提供该类上可用的属性。

¥All JavaScript and system errors raised by Node.js inherit from, or are instances of, the standard JavaScript <Error> class and are guaranteed to provide at least the properties available on that class.