0
我有一些這樣的代碼的打擊, 如果擲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);
}
});