EventTarget 错误处理


EventTarget error handling】

当注册的事件监听器抛出错误(或返回一个被拒绝的 Promise)时,默认情况下,该错误会被视为 process.nextTick() 上的未捕获异常。这意味着 EventTarget 中的未捕获异常默认会终止 Node.js 进程。

【When a registered event listener throws (or returns a Promise that rejects), by default the error is treated as an uncaught exception on process.nextTick(). This means uncaught exceptions in EventTargets will terminate the Node.js process by default.】

在事件监听器中抛出异常 不会 阻止其他注册的处理程序被调用。

【Throwing within an event listener will not stop the other registered handlers from being invoked.】

EventTarget 并不像 EventEmitter 那样对 'error' 类型事件实现任何特殊的默认处理。

【The EventTarget does not implement any special default handling for 'error' type events like EventEmitter.】

当前,错误首先会被转发到 process.on('error') 事件,然后才会到达 process.on('uncaughtException')。这种行为已被弃用,并将在未来的版本中更改,以使 EventTarget 与其他 Node.js API 保持一致。任何依赖 process.on('error') 事件的代码都应与新的行为保持一致。

【Currently errors are first forwarded to the process.on('error') event before reaching process.on('uncaughtException'). This behavior is deprecated and will change in a future release to align EventTarget with other Node.js APIs. Any code relying on the process.on('error') event should be aligned with the new behavior.】