如果它在 MongoClients函数内,我try
不会catch
出错connect
Linux (Mint, Tessa)
Node.js v10.16.0(使用 ES6 和nodemon)
MongoClient(来自 mongodb npm 存储库)
如果我试试这个:
try {
throw new Error('This is error');
} catch(e) {
console.log(`Catched: ${e}`);
}
我得到了干净的出口(很好 - 工作)
Catched: Error: This is error
[nodemon] clean exit - waiting for changes before restart
但这不起作用
如果我在 MongoDB 的连接函数中尝试:
try {
MongoClient.connect(config.url, config.options, (err, db) => {
if (err) { throw new Error('This is error'); }
});
} catch (err) {
console.log(`Catched: ${e}`);
}
我的应用程序崩溃了
Error: This is error
[nodemon] app crashed - waiting for file changes before starting...
所以这意味着它没有捕捉到我的异常。
www说
相关分类