最近在看js高程第四版,看到异步函数有点疑惑,想问问大佬们。
js异步函数中,拒绝期约的错误不会被异步函数捕获。
async function foo(){
console.log(1)
Promise.reject(3) // 疑问:promise实现了thenable接口,这样的话,为什么下面的catche语句不能执行?为啥捕获不了?
}
foo().catch(console.log)
console.log(2)
// 1
// 2
// Uncaught (in promise): 3
js异步函数中,拒绝期约的错误不会被异步函数捕获。
async function foo(){
console.log(1)
Promise.reject(3) // 疑问:promise实现了thenable接口,这样的话,为什么下面的catche语句不能执行?为啥捕获不了?
}
foo().catch(console.log)
console.log(2)
// 1
// 2
// Uncaught (in promise): 3
展开
2
1