| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2601c06 commit a0c117b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,15 +141,15 @@ the first argument will be passed as `null`. | |||
| 141 | 141 | const fs = require('fs'); | |
| 142 | 142 | ||
| 143 | 143 | function nodeStyleCallback(err, data) { | |
| 144 | - if (err) { | ||
| 145 | - console.error('There was an error', err); | ||
| 146 | - return; | ||
| 147 | - } | ||
| 148 | - console.log(data); | ||
| 144 | + if (err) { | ||
| 145 | + console.error('There was an error', err); | ||
| 146 | + return; | ||
| 147 | + } | ||
| 148 | + console.log(data); | ||
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | 151 | fs.readFile('/some/file/that/does-not-exist', nodeStyleCallback); | |
| 152 | - fs.readFile('/some/file/that/does-exist', nodeStyleCallback) | ||
| 152 | + fs.readFile('/some/file/that/does-exist', nodeStyleCallback); | ||
| 153 | 153 | ``` | |
| 154 | 154 | ||
| 155 | 155 | The JavaScript `try / catch` mechanism **cannot** be used to intercept errors | |
@@ -167,15 +167,15 @@ try { | |||
| 167 | 167 | throw err; | |
| 168 | 168 | } | |
| 169 | 169 | }); | |
| 170 | - } catch(err) { | ||
| 170 | + } catch (err) { | ||
| 171 | 171 | // This will not catch the throw! | |
| 172 | - console.log(err); | ||
| 172 | + console.error(err); | ||
| 173 | 173 | } | |
| 174 | 174 | ``` | |
| 175 | 175 | ||
| 176 | 176 | This will not work because the callback function passed to `fs.readFile()` is | |
| 177 | 177 | called asynchronously. By the time the callback has been called, the | |
| 178 | - surrounding code (including the `try { } catch(err) { }` block will have | ||
| 178 | + surrounding code (including the `try { } catch (err) { }` block will have | ||
| 179 | 179 | already exited. Throwing an error inside the callback **can crash the Node.js | |
| 180 | 180 | process** in most cases. If [domains][] are enabled, or a handler has been | |
| 181 | 181 | registered with `process.on('uncaughtException')`, such errors can be | |
@@ -217,7 +217,7 @@ a string representing the location in the code at which | |||
| 217 | 217 | ```js | |
| 218 | 218 | const myObject = {}; | |
| 219 | 219 | Error.captureStackTrace(myObject); | |
| 220 | - myObject.stack // similar to `new Error().stack` | ||
| 220 | + myObject.stack; // similar to `new Error().stack` | ||
| 221 | 221 | ``` | |
| 222 | 222 | ||
| 223 | 223 | The first line of the trace, instead of being prefixed with `ErrorType: | |
@@ -238,7 +238,7 @@ function MyError() { | |||
| 238 | 238 | // Without passing MyError to captureStackTrace, the MyError | |
| 239 | 239 | // frame would show up in the .stack property. By passing | |
| 240 | 240 | // the constructor, we omit that frame and all frames above it. | |
| 241 | - new MyError().stack | ||
| 241 | + new MyError().stack; | ||
| 242 | 242 | ``` | |
| 243 | 243 | ||
| 244 | 244 | ### Error.stackTraceLimit | |
@@ -255,7 +255,7 @@ will affect any stack trace captured *after* the value has been changed. | |||
| 255 | 255 | If set to a non-number value, or set to a negative number, stack traces will | |
| 256 | 256 | not capture any frames. | |
| 257 | 257 | ||
| 258 | - #### error.message | ||
| 258 | + ### error.message | ||
| 259 | 259 | ||
| 260 | 260 | * {String} | |
| 261 | 261 | ||
@@ -267,11 +267,11 @@ the stack trace of the `Error`, however changing this property after the | |||
| 267 | 267 | ||
| 268 | 268 | ```js | |
| 269 | 269 | const err = new Error('The message'); | |
| 270 | - console.log(err.message); | ||
| 270 | + console.error(err.message); | ||
| 271 | 271 | // Prints: The message | |
| 272 | 272 | ``` | |
| 273 | 273 | ||
| 274 | - #### error.stack | ||
| 274 | + ### error.stack | ||
| 275 | 275 | ||
| 276 | 276 | * {String} | |
| 277 | 277 | ||
@@ -359,7 +359,7 @@ For example: | |||
| 359 | 359 | ||
| 360 | 360 | ```js | |
| 361 | 361 | require('net').connect(-1); | |
| 362 | - // throws RangeError, port should be > 0 && < 65536 | ||
| 362 | + // throws "RangeError: "port" option should be >= 0 and < 65536: -1" | ||
| 363 | 363 | ``` | |
| 364 | 364 | ||
| 365 | 365 | Node.js will generate and throw `RangeError` instances *immediately* as a form | |
@@ -379,19 +379,6 @@ doesNotExist; | |||
| 379 | 379 | // throws ReferenceError, doesNotExist is not a variable in this program. | |
| 380 | 380 | ``` | |
| 381 | 381 | ||
| 382 | - `ReferenceError` instances will have an `error.arguments` property whose value | ||
| 383 | - is an array containing a single element: a string representing the variable | ||
| 384 | - that was not defined. | ||
| 385 | - | ||
| 386 | - ```js | ||
| 387 | - const assert = require('assert'); | ||
| 388 | - try { | ||
| 389 | - doesNotExist; | ||
| 390 | - } catch(err) { | ||
| 391 | - assert(err.arguments[0], 'doesNotExist'); | ||
| 392 | - } | ||
| 393 | - ``` | ||
| 394 | - | ||
| 395 | 382 | Unless an application is dynamically generating and running code, | |
| 396 | 383 | `ReferenceError` instances should always be considered a bug in the code | |
| 397 | 384 | or its dependencies. | |
@@ -407,7 +394,7 @@ program. | |||
| 407 | 394 | ```js | |
| 408 | 395 | try { | |
| 409 | 396 | require('vm').runInThisContext('binary ! isNotOk'); | |
| 410 | - } catch(err) { | ||
| 397 | + } catch (err) { | ||
| 411 | 398 | // err will be a SyntaxError | |
| 412 | 399 | } | |
| 413 | 400 | ``` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments