[英]Do I need to explicitly catch and re-throw exceptions when awaiting an asynchronous function?
If I have 如果我有
async function bar() {
throw 'bar';
}
What's the difference between 有什么区别
async function foo() {
await bar();
}
and 和
async function foo() {
try {
await bar();
} catch(e) {
throw e;
}
}
I heard that I need to explicitly catch and re-throw exceptions inside asynchronous functions, but I assumed catch(e) { throw e; }
我听说我需要在异步函数中显式捕获并重新抛出异常,但我假设catch(e) { throw e; }
catch(e) { throw e; }
is redundant (if there's no extra processing or logging done before the exception is thrown again). catch(e) { throw e; }
是多余的(如果没有额外的处理或异常被抛出再次之前记录完成)。 I believe that's how it is in some other languages; 我相信它在某些其他语言中是如何形成的; what about JavaScript? 那JavaScript怎么样?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.