J'ai un code comme coup, si un jet 1, l'affichage devientne peut pas attraper erreur dans nodejs et MongoDB
catch in main
throw 1
si un jet 2, l'affichage sera
catch in test
throw 2
mais si Je veux l'affichage comme ceci,
catch in test
throw 2
catch in main
throw 2
comment puis-je faire?
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);
}
});