Skip to content

Commit

Permalink
doc: discourage error event
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
benjamingr committed Feb 11, 2021
1 parent 295e766 commit cf5f6af
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,12 +1247,21 @@ target.addEventListener('foo', handler4, { once: true });
### `EventTarget` error handling

When a registered event listener throws (or returns a Promise that rejects),
by default the error is forwarded to the `process.on('error')` event
on `process.nextTick()`. Throwing within an event listener will *not* stop
the other registered handlers from being invoked.
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.

The `EventTarget` does not implement any special default handling for
`'error'` type events.
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.

### Class: `Event`
<!-- YAML
Expand Down

0 comments on commit cf5f6af

Please sign in to comment.