process.on(“ uncaughtException”)无法捕获异常

时间:2019-02-13 12:14:42

标签: node.js express

我在index.js中有以下代码

const winston = require('winston');
require('winston-mongodb');

process.on('uncaughtException', (ex) => {
  console.log('WE GOT AN UNCAUGHT EXCEPTION');
  winston.error(ex.message, ex);
});

这就是我期望它起作用的方式。 index.js将引发一个未捕获的异常。然后console.log将显示消息,而winston库将记录错误并将其存储在日志文件中。

实际上,以上所有方法均无效,甚至console.log也无效。因此,我认为错误永远不会发生。

我使用:节点-> v10.15.1
npm-> 6.4.1
温斯顿-> 2.4.0
winston-mongodb-> 3.0.0

0 个答案:

没有答案