-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatch.ts
59 lines (51 loc) · 901 Bytes
/
catch.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function main() {
try {
setTimeout(() => {
throw new Error('async error')
}, 1000)
} catch(e) {
console.log(e, 'err')
console.log('continue...')
}
}
main();
const promiseFetch = () => new Promise((reslove) => {
reslove();
})
function main2() {
try {
promiseFetch().then(() => {
throw new Error('err')
})
} catch(e) {
console.log(e, 'eeee');
console.log('continue');
}
}
function main3() {
promiseFetch().then(() => {
return new Error('err');
}).catch(e => {
console.log(e, 'promise-catch: eee');
})
}
function main4() {
promiseFetch().then(() => {
return new Error('err');
}).then(e => {
console.log(e, 'promise-then: eee');
})
}
const fn = (cb: () => void) => {
cb();
}
function main6() {
try {
fn(() => {
throw new Error('123');
})
} catch(e) {
console.log('error');
}
}
main6();