Promise里捕捉错误的最佳实践

Promise里的同步部分不需要try catch

new Promise((resolve, reject) => {
throw new Error('error');
setTimeout(() => { }, 100);
}).catch(e => {
console.log('log', e);
});;

异步部分需要try catch

new Promise((resolve, reject) => {

    setTimeout(() => {
try{
throw new Error('error');
} catch(e) {
reject(e);
}
}, 100);
}).catch(e => {
console.log('log', e);
});;
上一篇:Atitit.500 503 404错误处理最佳实践oak


下一篇:CF Preparing Olympiad (DFS)