[英]Node giving UnhandledPromiseRejection warning, when I'm *sure* I'm catching the rejection
[英]UnhandledPromiseRejection despite catching expection
在下面的代码中
// file: main.js
class A {
async start() {
throw 'error';
}
}
module.exports = A;
// file index.js
var r = require('./main.js');
let v = new r();
try {
v.start(); // error is caught when I use r.start() though
} catch (e) {
console.error(e);
}
我是 Javascript 和 Node.js 的新手,当我清楚地捕捉到异常时,Node.js 会抛出 UnhandledPromiseRejection,为什么会发生这种情况?
此错误源于在没有 catch 块的情况下抛出异步 function
查看原因:
节点 --trace-warnings index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.