@@ -149,10 +149,11 @@ most convenient for scripts).
149149added: v0.1.18
150150-->
151151
152- The ` 'uncaughtException' ` event is emitted when an exception bubbles all the
153- way back to the event loop. By default, Node.js handles such exceptions by
154- printing the stack trace to ` stderr ` and exiting. Adding a handler for the
155- ` 'uncaughtException' ` event overrides this default behavior.
152+ The ` 'uncaughtException' ` event is emitted when an uncaught JavaScript
153+ exception bubbles all the way back to the event loop. By default, Node.js
154+ handles such exceptions by printing the stack trace to ` stderr ` and exiting.
155+ Adding a handler for the ` 'uncaughtException' ` event overrides this default
156+ behavior.
156157
157158The listener function is called with the ` Error ` object passed as the only
158159argument.
@@ -161,7 +162,7 @@ For example:
161162
162163``` js
163164process .on (' uncaughtException' , (err ) => {
164- console . log ( ` Caught exception: ${ err} ` );
165+ fs . writeSync ( 1 , ` Caught exception: ${ err} ` );
165166});
166167
167168setTimeout (() => {
@@ -192,20 +193,24 @@ times nothing happens - but the 10th time, the system becomes corrupted.
192193
193194The correct use of ` 'uncaughtException' ` is to perform synchronous cleanup
194195of allocated resources (e.g. file descriptors, handles, etc) before shutting
195- down the process. It is not safe to resume normal operation after
196- ` 'uncaughtException' ` .
196+ down the process. ** It is not safe to resume normal operation after
197+ ` 'uncaughtException' ` .**
198+
199+ To restart a crashed application in a more reliable way, whether ` uncaughtException `
200+ is emitted or not, an external monitor should be employed in a separate process
201+ to detect application failures and recover or restart as needed.
197202
198203### Event: 'unhandledRejection'
199204<!-- YAML
200205added: v1.4.1
201206-->
202207
203208The ` 'unhandledRejection ` ' event is emitted whenever a ` Promise ` is rejected and
204- no error handler is attached to the promise within a turn of the event loop.
209+ no error handler is attached to the promise within a turn of the event loop.
205210When programming with Promises, exceptions are encapsulated as "rejected
206211promises". Rejections can be caught and handled using [ ` promise.catch() ` ] [ ] and
207212are propagated through a ` Promise ` chain. The ` 'unhandledRejection' ` event is
208- useful for detecting and keeping track of promises that were rejected whose
213+ useful for detecting and keeping track of promises that were rejected whose
209214rejections have not yet been handled.
210215
211216The listener function is called with the following arguments:
@@ -637,7 +642,7 @@ An example of this object looks like:
637642 SHLVL : ' 1' ,
638643 HOME : ' /Users/maciej' ,
639644 LOGNAME : ' maciej' ,
640- _: ' /usr/local/bin/node'
645+ _: ' /usr/local/bin/node'
641646}
642647```
643648
@@ -1108,10 +1113,10 @@ console.log(util.inspect(process.memoryUsage()));
11081113Will generate:
11091114
11101115``` js
1111- {
1116+ {
11121117 rss: 4935680 ,
11131118 heapTotal: 1826816 ,
1114- heapUsed: 650472
1119+ heapUsed: 650472
11151120}
11161121```
11171122
0 commit comments