Review
- 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:
- Throw
try…catchblocks- Callbacks
- Promises or Async/await
- Event emitters(events)
- Middleware
- unhandledRejection, uncaughtException