Problem
My try
doesn't catch
error if it is inside of MongoClients connect
function
Environment
- Linux (Mint, Tessa)
- Node.js v10.16.0 (using ES6 with nodemon)
- MongoClient (from mongodb npm repository)
Example
If I try this:
try {
throw new Error('This is error');
} catch(e) {
console.log(`Catched: ${e}`);
}
I get clean exit (it's fine - working)
Catched: Error: This is error
[nodemon] clean exit - waiting for changes before restart
But this doesn't work
If I try it in MongoDBs connect function:
try {
MongoClient.connect(config.url, config.options, (err, db) => {
if (err) { throw new Error('This is error'); }
});
} catch (err) {
console.log(`Catched: ${e}`);
}
I get app crashed
Error: This is error
[nodemon] app crashed - waiting for file changes before starting...
So it means it didn't catch my exception.