node

xiaoxiao2021-02-28  79

1.process

1.Event: 'rejectionHandled' && 'unhandledRejection' 

Promise对象触发了reject&同时存在一个handled方法(Promise.catch())来处理reject的时候,会emit一个rejectionHandled事件,

如果不存在handled方法,则触发'unhandledRejection' 事件

异步代码中,未处理的reject的list增加时emit的unhandledRejection事件,

 展开原码

2.Event: 'uncaughtException' 当未捕获的js异常回到事件环中,会触发uncaughtException事件。

无callback函数时,nodejs默认将打印异常的stack trace给stderr然后退出。

同步代码中,未处理异常list增加的时候会发出uncaughtException事件

In synchronous code, the 'uncaughtException' event is emitted when the list of unhandled exceptions grows.

In asynchronous code, the 'unhandledRejection' event is emitted when the list of unhandled rejections grows, and the 'rejectionHandled' event is emitted when the list of unhandled rejections shrinks.

转载请注明原文地址: https://www.6miu.com/read-56776.html

最新回复(0)