Error 错误
在 Node.js 中运行的应用程序通常会遇到四类错误:
- 标准的 JavaScript 错误,例如 <EvalError>、<SyntaxError>、<RangeError>、<ReferenceError>、<TypeError> 和 <URIError>。
- 由底层操作系统约束触发的系统错误,例如尝试打开不存在的文件或尝试通过关闭的套接字发送数据。
- 由应用程序代码触发的用户指定的错误。
AssertionError
是特殊的错误类,当 Node.js 检测到不应该发生的异常逻辑违规时会触发。 这些通常由assert
模块引发。
Node.js 引发的所有 JavaScript 和系统错误都继承自标准的 JavaScript <Error> 类(或者是其实例),并且保证至少提供该类上可用的属性。
Applications running in Node.js will generally experience four categories of errors:
- 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
s 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 theassert
module.
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.