async...await...异常捕获的方式
async function catchError(func) {
try {
const res = await func()
return [null, res]
} catch (e) {
return [e, null]
}
}

(async () => {

const [err, res] = await catchError(你的函数方法)
if (err) {
// 错误处理
}
// 正常处理
}
})();
展开
评论