06 Error Handing

Review

  1. 2023-10-10 22:36

一、Introduction #

Error handling is a way to find bugs and solve them as quickly as humanly possible. The errors in Node.js can be either operation or programmer errors.

有两种错误

  • 编程错误:程序员写出的错误(语法错误、引用错误、类型错误)
  • 业务错误:外部因素导致服务不能正常运行(超时、服务端异常、输入错误)

Error handling techniques #

There are four fundamental strategies to report errors in Node.js:

  1. Throw
  2. try…catch blocks
  3. Callbacks
  4. Promises or Async/await
  5. Event emitters(events)
  6. Middleware
  7. unhandledRejection, uncaughtException

Reference #