@@ -141,15 +141,15 @@ the first argument will be passed as `null`.
141141const fs = require('fs');
142142
143143function 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);
149149}
150150
151151fs.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);
153153```
154154
155155The JavaScript `try / catch` mechanism **cannot** be used to intercept errors
@@ -167,15 +167,15 @@ try {
167167 throw err;
168168 }
169169 });
170- } catch(err) {
170+ } catch (err) {
171171 // This will not catch the throw!
172- console.log (err);
172+ console.error (err);
173173}
174174```
175175
176176This will not work because the callback function passed to `fs.readFile()` is
177177called 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
179179already exited. Throwing an error inside the callback **can crash the Node.js
180180process** in most cases. If [domains][] are enabled, or a handler has been
181181registered with `process.on('uncaughtException')`, such errors can be
@@ -217,7 +217,7 @@ a string representing the location in the code at which
217217```js
218218const myObject = {};
219219Error.captureStackTrace(myObject);
220- myObject.stack // similar to `new Error().stack`
220+ myObject.stack; // similar to `new Error().stack`
221221```
222222
223223The first line of the trace, instead of being prefixed with `ErrorType:
@@ -238,7 +238,7 @@ function MyError() {
238238// Without passing MyError to captureStackTrace, the MyError
239239// frame would show up in the .stack property. By passing
240240// the constructor, we omit that frame and all frames above it.
241- new MyError().stack
241+ new MyError().stack;
242242```
243243
244244### Error.stackTraceLimit
@@ -255,7 +255,7 @@ will affect any stack trace captured *after* the value has been changed.
255255If set to a non-number value, or set to a negative number, stack traces will
256256not capture any frames.
257257
258- #### error.message
258+ ### error.message
259259
260260* {String}
261261
@@ -267,11 +267,11 @@ the stack trace of the `Error`, however changing this property after the
267267
268268```js
269269const err = new Error('The message');
270- console.log (err.message);
270+ console.error (err.message);
271271// Prints: The message
272272```
273273
274- #### error.stack
274+ ### error.stack
275275
276276* {String}
277277
@@ -359,7 +359,7 @@ For example:
359359
360360```js
361361require('net').connect(-1);
362- // throws RangeError, port should be > 0 && < 65536
362+ // throws " RangeError: " port" option should be >= 0 and < 65536: -1"
363363```
364364
365365Node.js will generate and throw `RangeError` instances *immediately* as a form
@@ -379,19 +379,6 @@ doesNotExist;
379379 // throws ReferenceError, doesNotExist is not a variable in this program.
380380```
381381
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-
395382Unless an application is dynamically generating and running code,
396383`ReferenceError` instances should always be considered a bug in the code
397384or its dependencies.
@@ -407,7 +394,7 @@ program.
407394```js
408395try {
409396 require('vm').runInThisContext('binary ! isNotOk');
410- } catch(err) {
397+ } catch (err) {
411398 // err will be a SyntaxError
412399}
413400```
0 commit comments