const fn = async function() {
throw 1;
};
fn()
.then(data => console.log('then: ' + data))
.catch(data => console.log('catch: ' + data))
.finally(data => console.log('finally'));
// catch: 1
// finally
请问这么写规范吗?
这样写catch确实可以捕获到,但是不知道这么写是不是规范的?
不用promise,想用async,同时想和promise一样,有 then
catch
finally
的处理
async就是promise的语法糖,用then和awit其实是一样的,你也可以这样写