【发布时间】:2015-12-02 00:59:55
【问题描述】:
我有一些类似打击的代码, 如果抛出 1,则显示为
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);
}
});
【问题讨论】:
标签: node.js mongodb try-catch throw