@@ -128,35 +128,36 @@ they are thrown *after* the calling code has already exited.
128
128
Developers must refer to the documentation for each method to determine
129
129
exactly how errors raised by those methods are propagated.
130
130
131
- ### Node.js style callbacks
131
+ ### Error-first callbacks
132
132
133
133
<!-- type=misc-->
134
134
135
135
Most asynchronous methods exposed by the Node.js core API follow an idiomatic
136
- pattern referred to as a "Node.js style callback". With this pattern, a
137
- callback function is passed to the method as an argument. When the operation
138
- either completes or an error is raised, the callback function is called with
139
- the Error object (if any) passed as the first argument. If no error was raised,
140
- the first argument will be passed as ` null ` .
136
+ pattern referred to as an _ error-first callback_ (sometimes referred to as
137
+ a _ Node.js style callback_ ). With this pattern, a callback function is passed
138
+ to the method as an argument. When the operation either completes or an error
139
+ is raised, the callback function is called with
140
+ the Error object (if any) passed as the first argument. If no error was
141
+ raised, the first argument will be passed as ` null ` .
141
142
142
143
``` js
143
144
const fs = require (' fs' );
144
145
145
- function nodeStyleCallback (err , data ) {
146
+ function errorFirstCallback (err , data ) {
146
147
if (err) {
147
148
console .error (' There was an error' , err);
148
149
return ;
149
150
}
150
151
console .log (data);
151
152
}
152
153
153
- fs .readFile (' /some/file/that/does-not-exist' , nodeStyleCallback );
154
- fs .readFile (' /some/file/that/does-exist' , nodeStyleCallback );
154
+ fs .readFile (' /some/file/that/does-not-exist' , errorFirstCallback );
155
+ fs .readFile (' /some/file/that/does-exist' , errorFirstCallback );
155
156
```
156
157
157
158
The JavaScript ` try / catch ` mechanism ** cannot** be used to intercept errors
158
159
generated by asynchronous APIs. A common mistake for beginners is to try to
159
- use ` throw ` inside a Node.js style callback:
160
+ use ` throw ` inside an error-first callback:
160
161
161
162
``` js
162
163
// THIS WILL NOT WORK:
0 commit comments