【发布时间】:2020-05-17 12:44:17
【问题描述】:
const client = http2.
connect('https://domain.doesnt.exist').
on('error', e => {
console.error(e.message);
});
在 Node.js 13.6.0 上,即使提供了错误侦听器,上述代码也会导致整个进程崩溃。
我将如何避免它?
【问题讨论】:
const client = http2.
connect('https://domain.doesnt.exist').
on('error', e => {
console.error(e.message);
});
在 Node.js 13.6.0 上,即使提供了错误侦听器,上述代码也会导致整个进程崩溃。
我将如何避免它?
【问题讨论】:
您可以使用uncaughtException 事件记录所有未捕获的异常..
process.on('uncaughtException', err => {
console.log(err.message);
console.log(err.stack);
process.exit(1)
})
【讨论】: