From 58d986f2ad73d9825d6d2e4e9f287dcd55dc73b0 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 9 Nov 2017 17:58:42 +0100 Subject: [PATCH] doc: avoid mentioning 'uncaughtException' Avoid suggesting using `'uncaughtException'` for emitted errors. PR-URL: https://github.com/nodejs/node/pull/16905 Reviewed-By: Ben Noordhuis --- doc/api/events.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/doc/api/events.md b/doc/api/events.md index b08dc23d322e1a..443137f1705e26 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -142,20 +142,8 @@ myEmitter.emit('error', new Error('whoops!')); // Throws and crashes Node.js ``` -To guard against crashing the Node.js process, a listener can be registered -on the [`process` object's `uncaughtException` event][] or the [`domain`][] module -can be used. (Note, however, that the `domain` module has been deprecated.) - -```js -const myEmitter = new MyEmitter(); - -process.on('uncaughtException', (err) => { - console.error('whoops! there was an error'); -}); - -myEmitter.emit('error', new Error('whoops!')); -// Prints: whoops! there was an error -``` +To guard against crashing the Node.js process the [`domain`][] module can be +used. (Note, however, that the `domain` module has been deprecated.) As a best practice, listeners should always be added for the `'error'` events. @@ -594,5 +582,4 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. [`fs.ReadStream`]: fs.html#fs_class_fs_readstream [`net.Server`]: net.html#net_class_net_server [`process.on('warning')`]: process.html#process_event_warning -[`process` object's `uncaughtException` event]: process.html#process_event_uncaughtexception [stream]: stream.html