У меня есть некоторый код, как удар, если бросок 1, дисплей будетНе удается поймать ошибку в nodejs и MongoDB
catch in main
throw 1
если бросок 2, дисплей будет
catch in test
throw 2
, но если Я хочу показать, как это,
catch in test
throw 2
catch in main
throw 2
как я могу это сделать?
function test(database)
{
if(1) throw 'throw 1'; //if throw at here, 'catch in main' will display
var col=database.collection('profiles');
col.findOne({"oo" : 'xx'})
.then(function(doc){
throw 'throw 2'; //if throw at here, 'catch in main' will [NOT] display
})
.catch(function(e){
console.log('catch in test');
console.log(e);
throw e;
});
}
MongoClient.connect(url, function(err, database) {
try{
test(database);
}catch(e){
console.log('catch in main'); //if throw 2, this line will [NOT] run
console.log(e);
}
});