【发布时间】:2011-02-22 21:47:55
【问题描述】:
我有一个 node.js 服务器,我希望能够在不崩溃的情况下处理异常,并且我的代码有点像下面。我想知道的是,有了所有事件驱动的出色功能、回调和 lambda 以及所有这些,我的异常是否仍会被我的主要入口点捕获?
try {
http.get(..., function(results) {
// Might get an exception here
results.on('data', function () {
// Might also get an exception here
});
results.on('end', function () {
// Might also get an exception here
});
});
} catch(e) {
// Will the exceptions from the lambdas be caught here?
console.log('Nicely caught error: (' + e.name + '): ' + e.message);
}
谢谢
【问题讨论】:
标签: javascript exception node.js