Skip to content

Commit 3464c9f

Browse files
benjamingrdanielleadams
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 e28fa6c commit 3464c9f

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
@@ -1247,12 +1247,21 @@ target.addEventListener('foo', handler4, { once: true });
12471247
### `EventTarget` error handling
12481248

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

1254-
The `EventTarget` does not implement any special default handling for
1255-
`'error'` type events.
1254+
Throwing within an event listener will *not* stop the other registered handlers
1255+
from being invoked.
1256+
1257+
The `EventTarget` does not implement any special default handling for `'error'`
1258+
type events like `EventEmitter`.
1259+
1260+
Currently errors are first forwarded to the `process.on('error')` event
1261+
before reaching `process.on('uncaughtException')`. This behavior is
1262+
deprecated and will change in a future release to align `EventTarget` with
1263+
other Node.js APIs. Any code relying on the `process.on('error')` event should
1264+
be aligned with the new behavior.
12561265

12571266
### Class: `Event`
12581267
<!-- YAML

0 commit comments

Comments
 (0)