Node.js v18.12.1 documentation


Table of contents

Errors#

Applications running in Node.js will generally experience four categories of errors:在Node.js中运行的应用程序通常会遇到四类错误:

  • 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. 是一类特殊的错误,当Node.js检测到不应该发生的异常逻辑冲突时,会触发该类错误。These are raised typically by the node:assert module.这些通常由node:assert模块引发。

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引发的所有JavaScript和系统错误都继承自标准JavaScript<Error>类,或是标准JavaScript<Error>类的实例,并保证至少提供该类上可用的属性。