我试图用 async/await 捕获承诺中的错误,但以下代码会导致“未捕获的错误...”
function messup() {
var promise = new Promise(function(resolve, reject){
setTimeout(function() {
throw new Error("Thrown from messup()");
resolve('hello from messup function');
}, 1000);
});
return promise;
}
async function waitForMe() {
try {
await messup();
}catch(e) {
console.log ('*****Error successfully caught! *****');
}
}
waitForMe()
扬帆大鱼
呼唤远方
相关分类