EventTarget 的错误处理
当注册的事件监听器抛出错误(或返回拒绝的 Promise)时,默认情况下,错误将被视为 process.nextTick()
上的未捕获异常。
这意味着 EventTarget
中未捕获的异常将默认终止 Node.js 进程。
在事件监听器中抛出错误不会阻止其他注册的句柄被调用。
EventTarget
没有为 'error'
类型的事件(如 EventEmitter
)实现任何特殊的默认处理。
当前错误在到达 process.on('uncaughtException')
之前首先转发到 process.on('error')
事件。
此行为已弃用,并将在未来版本中更改,以使 EventTarget
与其他 Node.js API 保持一致。
任何依赖 process.on('error')
事件的代码都应与新行为保持一致。
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 EventTarget
s will
terminate the Node.js process by default.
Throwing within an event listener will not stop the other registered handlers from being invoked.
The EventTarget
does not implement any special default handling for 'error'
type events like EventEmitter
.
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.