-
Notifications
You must be signed in to change notification settings - Fork 0
/
promise.ts
57 lines (45 loc) · 930 Bytes
/
promise.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
const p1 = new Promise((reslove, reject) => {
if(1) {
reject('p1 error');
}
});
p1.catch((msg) => console.log(msg));
const p2 = new Promise((reslove, reject) => {
if(1) {
throw new Error('p2 error')
}
});
p2.catch((e) => console.log(e.message));
function main1() {
try {
new Promise(() => {
throw new Error('promise1 error')
}).catch((e) => {
});
} catch(e) {
console.log(e.message);
}
}
function main2() {
try {
Promise.reject('promise2 error').catch();
} catch(e) {
console.log(e.message);
}
}
const p3 = () => new Promise((reslove, reject) => {
setTimeout(() => {
reject('async error');
})
});
function main3() {
p3().catch(e => console.log(e));
}
// main3();
Promise.resolve(1).then(function (value) {
new Promise((reslove, reject) => {
reject('123');
}).catch(e => { console.log(e)});
}, function (err) {
console.log(err, 'err');
});