Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

node8中 Async/Await 如何优雅的捕捉错误?

$
0
0

之前写习惯了es6,捕获错误一般是通过回调来实现 比如:

foo('A', (err, result) = >{
	console.log(err);
});

但是现在因为node8发布LTS版本,就开始用node8

用node8当然少不了 Async/Await 现在我捕捉错误用try/catch去捕捉

try{
	await foo();
}catch(err){
	console.log(err);
}

问题

众所周知,try/catch会影响性能,是否有更好的方法捕捉错误?


Viewing all articles
Browse latest Browse all 14821

Trending Articles