express中,对于uncaughtException异常捕获后的处理以及一些疑问的请教
发布于 19天前 作者 VinTurtle 218 次浏览 来自 问答

参考了一篇【 Node 出现 uncaughtException 之后的优雅退出方案】的文章的文章 其中有几点不太明白,想请教一下: 1.文章中说,使用domain无法捕获所有的uncaughtException,需要用process.on(‘uncaughtException’)来捕获,但是官方文档上又是不建 议使用process.on('uncaughtException’,function(err){ … }) Note that uncaughtException is a very crude mechanism for exception handling and may be removed in the future. Don’t use it, use domains instead. If you do use it, restart your application after every unhandled exception!* 那我到底是用还是不用啊 2.文章中提到,"domain 捕获到错误时依然会丢失堆栈信息,此时已经无法保证程序的健康运行,必须退出" 这里不是很明白,为什么要退出进程,这样不是会影响其他连接着的用户吗,还是说不退出会造成内存泄露之类的问题呢

我现在的代码如下: app.use(function (req, res, next) { var reqDomain = domain.create(); reqDomain.on('error’, function (err) { try { var killtimer = setTimeout(function() { process.exit(1); }, 5000); killtimer.unref(); raygunClient.send(err); res.send(500); } catch (error) { raygunClient.send(error); } }); reqDomain.run(next); }); 我现在在捕获到异常时用raygun去trace异常信息,一般大家都是怎么处理的? 不知道我这么写对不对

回到顶部