var customError = function(){
try{
setTimeout(function(){
console.log("time out called");
throw new Error ("Error in call back");
},5000);
}catch(e){
console.log(e);
}
}
customError();
process.on('uncaughtException', function (err) {
console.log(err);
})
我读了一些博客,发现我们可以使用“uncaughtException”进程事件来处理在回调中发生的错误。但另一方面,我读取而不是“uncaughtException”,你应该使用承诺库。但“uncaughtException”事件适合我。我只想知道是否最好的做法来处理回调错误或不?最好的做法是绑定uncaughtException事件来处理callback nodejs中发生的错误?
谢谢,在阅读joyent文章后,我现在大部分的疑惑都被清除了。 –