1
2
3
4
5
6
7
8
9
function test() {
return new Promise((resolve) => {
throw Error('callback error')
})
}

test()
.then()
.catch(() => console.log('catch!'))

其实原本我以为回调中的异常可能得这样捕获:

1
2
3
4
5
try {
test()
} catch (e) {
// catch!
}

想多了。。


 评论