【发布时间】:2014-12-05 02:22:24
【问题描述】:
最初,uncaughtException 在我的代码中用于捕获所有未处理的异常。
process.on('uncaughtException', function (err) {
if ('stack' in err) {
console.log(err.stack);
}
});
不过也不是什么好办法,根据这个post,我们就知道了
`uncaughtException` is a very crude mechanism for exception handling and
may be removed in the future.
And use `domains` instead. If you do use it, restart your application
after every unhandled exception!
Do not use it as the node.js equivalent of On Error Resume Next.
另外,forever 模块是实现此目的的另一种好方法。
这是我的问题:
-
On Error Resume Next是什么意思? - 是否有关于如何处理 nodejs 中未捕获的异常的指南?
【问题讨论】:
-
on error resume next是 Visual Basic 6 中的一个选项(可能还有其他选项,但我从那里知道),它将忽略一段代码中的所有错误,并继续不间断地执行。这使得调试变得困难,因为您不会收到发生错误的特定消息,您只会得到一个无意义的结果。 -
那么,你为什么不使用“域”?
-
域名很可能很快就会被弃用。
-
@minitech 那么我们应该使用哪一个来处理错误?
-
@pmverma:我喜欢promises,我自己。 zangw:groups.google.com/forum/#!topic/nodejs/reTInaFyC2s
标签: javascript node.js exception-handling