首页 > 解决方案 > process.on("uncaughtException") 无法捕获异常

问题描述

我在 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
winston ->2.4.0
winston-mongodb ->3.0.0

标签: node.jsexpress

解决方案


推荐阅读