Skip to content

Commit b7c9366

Browse files
benjamingrtargos
authored andcommitted
doc: discourage error event
PR-URL: #37264 Refs: #37237 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent bf16d28 commit b7c9366

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

doc/api/events.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -1238,12 +1238,21 @@ target.addEventListener('foo', handler4, { once: true });
12381238
### `EventTarget` error handling
12391239

12401240
When a registered event listener throws (or returns a Promise that rejects),
1241-
by default the error is forwarded to the `process.on('error')` event
1242-
on `process.nextTick()`. Throwing within an event listener will *not* stop
1243-
the other registered handlers from being invoked.
1241+
by default the error is treated as an uncaught exception on
1242+
`process.nextTick()`. This means uncaught exceptions in `EventTarget`s will
1243+
terminate the Node.js process by default.
12441244

1245-
The `EventTarget` does not implement any special default handling for
1246-
`'error'` type events.
1245+
Throwing within an event listener will *not* stop the other registered handlers
1246+
from being invoked.
1247+
1248+
The `EventTarget` does not implement any special default handling for `'error'`
1249+
type events like `EventEmitter`.
1250+
1251+
Currently errors are first forwarded to the `process.on('error')` event
1252+
before reaching `process.on('uncaughtException')`. This behavior is
1253+
deprecated and will change in a future release to align `EventTarget` with
1254+
other Node.js APIs. Any code relying on the `process.on('error')` event should
1255+
be aligned with the new behavior.
12471256

12481257
### Class: `Event`
12491258
<!-- YAML

0 commit comments

Comments
 (0)