我有以下代码,不知道如何捕获此异常
async function start() {
try {
let result = await calc();
} catch (e) {
console.log('here I want to catch test exception', e);
}
}
function calc() {
return new Promise(r => setTimeout(x => {
throw 'TEST'
}, 1000));
}
start();
下面我展示了没有setTimeout的工作示例(但这不是我的情况)
async function start() {
try {
let result = await calc();
} catch (e) {
console.log('here I wana catch test exception:', e);
}
}
function calc() {
return new Promise(r => {
throw 'TEST'
});
}
start();