Skip to content

Commit a4dda99

Browse files
committed
Reorder catch example
1 parent d7d7358 commit a4dda99

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

JavaScript/4-catch.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
const readTextFile = filename => fs.promises.readFile(filename, 'utf8');
6+
7+
readTextFile('file1-.txt')
8+
.then(
9+
data => {
10+
console.dir({ file1: data });
11+
return readTextFile('file2.txt');
12+
},
13+
reason => {
14+
console.log('Cannot read file1.txt --- A');
15+
console.log(reason);
16+
}
17+
)
18+
.catch(
19+
reason => {
20+
console.log('Cannot read file1.txt --- B');
21+
console.log(reason);
22+
}
23+
)
24+
.then(data => {
25+
console.dir({ file2: data });
26+
return readTextFile('file3.txt');
27+
})
28+
.catch(reason => {
29+
console.log('Cannot read file2.txt');
30+
console.log(reason);
31+
})
32+
.then(data => {
33+
console.dir({ file3: data });
34+
})
35+
.catch(reason => {
36+
console.log('Cannot read file');
37+
console.log(reason);
38+
});

JavaScript/5-catch.js

-26
This file was deleted.

0 commit comments

Comments
 (0)