node.js - 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
解决方案
推荐阅读
- android - 以编程方式移动视图 Android
- r - 通过消除器将字符串拆分为无限数量的列
- c# - Selenium c#:在不使用 autoID / Class、Instance 等的情况下获取 RemoteWebElement 的新实例的最佳方法是什么?
- ajax - Prestashop 1.7.6.2 ajax 调用后台模块
- django - NoReverseMatch 在 /api/users/request-reset-email/
- pandas - 仅保留重复列上的第一个值(将 0 设置为其他值)
- html - 在 HTML 中显示选择的选项
- r - 将检测到的主题添加到输入数据
- python - 如何关闭“评估:plt.show() 在 3.00 秒后未完成”。VsCode 调试器中的警告?
- powershell - Powershell脚本运行但任务调度程序不会运行它