错误
\Errors
在 Node.js 中运行的应用通常会遇到以下几类错误:
\Applications running in Node.js will generally experience the following categories of errors:
-
标准的 JavaScript 错误,例如 <EvalError>、<SyntaxError>、<RangeError>、<ReferenceError>、<TypeError> 和 <URIError>。
\Standard JavaScript errors such as <EvalError>, <SyntaxError>, <RangeError>, <ReferenceError>, <TypeError>, and <URIError>.
-
标准
DOMException。\Standard
DOMExceptions. -
由底层操作系统约束触发的系统错误,例如尝试打开不存在的文件或尝试通过关闭的套接字发送数据。
\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.
-
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 thenode:assertmodule. -
由应用代码触发的用户指定的错误。
\User-specified errors triggered by application code.
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.
Node.js 引发的错误的 error.message 属性在任何版本中都可能被更改。请使用 error.code 来标识错误。对于 DOMException,使用 domException.name 来标识其类型。
\The error.message property of errors raised by Node.js may be changed in
any versions. Use error.code to identify an error instead. For a
DOMException, use domException.name to identify its type.