| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fc4df0d commit 9c274e3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,10 +149,11 @@ most convenient for scripts). | |||
| 149 | 149 | added: v0.1.18 | |
| 150 | 150 | --> | |
| 151 | 151 | ||
| 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. | ||
| 156 | 157 | ||
| 157 | 158 | The listener function is called with the `Error` object passed as the only | |
| 158 | 159 | argument. | |
@@ -161,7 +162,7 @@ For example: | |||
| 161 | 162 | ||
| 162 | 163 | ```js | |
| 163 | 164 | process.on('uncaughtException', (err) => { | |
| 164 | - console.log(`Caught exception: ${err}`); | ||
| 165 | + fs.writeSync(1, `Caught exception: ${err}`); | ||
| 165 | 166 | }); | |
| 166 | 167 | ||
| 167 | 168 | setTimeout(() => { | |
@@ -192,20 +193,24 @@ times nothing happens - but the 10th time, the system becomes corrupted. | |||
| 192 | 193 | ||
| 193 | 194 | The correct use of `'uncaughtException'` is to perform synchronous cleanup | |
| 194 | 195 | of 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. | ||
| 197 | 202 | ||
| 198 | 203 | ### Event: 'unhandledRejection' | |
| 199 | 204 | <!-- YAML | |
| 200 | 205 | added: v1.4.1 | |
| 201 | 206 | --> | |
| 202 | 207 | ||
| 203 | 208 | The `'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. | ||
| 205 | 210 | When programming with Promises, exceptions are encapsulated as "rejected | |
| 206 | 211 | promises". Rejections can be caught and handled using [`promise.catch()`][] and | |
| 207 | 212 | are 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 | ||
| 209 | 214 | rejections have not yet been handled. | |
| 210 | 215 | ||
| 211 | 216 | The listener function is called with the following arguments: | |
@@ -637,7 +642,7 @@ An example of this object looks like: | |||
| 637 | 642 | SHLVL: '1', | |
| 638 | 643 | HOME: '/Users/maciej', | |
| 639 | 644 | LOGNAME: 'maciej', | |
| 640 | - _: '/usr/local/bin/node' | ||
| 645 | + _: '/usr/local/bin/node' | ||
| 641 | 646 | } | |
| 642 | 647 | ``` | |
| 643 | 648 | ||
@@ -1108,10 +1113,10 @@ console.log(util.inspect(process.memoryUsage())); | |||
| 1108 | 1113 | Will generate: | |
| 1109 | 1114 | ||
| 1110 | 1115 | ```js | |
| 1111 | - { | ||
| 1116 | + { | ||
| 1112 | 1117 | rss: 4935680, | |
| 1113 | 1118 | heapTotal: 1826816, | |
| 1114 | - heapUsed: 650472 | ||
| 1119 | + heapUsed: 650472 | ||
| 1115 | 1120 | } | |
| 1116 | 1121 | ``` | |
| 1117 | 1122 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments