-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path4-catch.js
More file actions
34 lines (32 loc) · 755 Bytes
/
4-catch.js
File metadata and controls
34 lines (32 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const { readFile } = require('node:fs/promises');
readFile('file1.txt', 'utf8')
.then(
(data) => {
console.dir({ file1: data });
return readFile('file2.txt', 'utf8');
},
(reason) => {
console.log('1: Cannot read file1.txt');
console.log(reason);
},
)
.catch((reason) => {
console.log('2: Cannot read file1.txt');
console.log(reason);
})
.then((data) => {
console.dir({ file2: data });
return readFile('file3.txt', 'utf8');
})
.catch((reason) => {
console.log('Cannot read file2.txt');
console.log(reason);
})
.then((data) => {
console.dir({ file3: data });
})
.catch((reason) => {
console.log('Cannot read file');
console.log(reason);
});