【发布时间】:2017-12-20 12:46:30
【问题描述】:
【问题讨论】:
【问题讨论】:
侦听uncaughtException 事件并记录您收到的任何错误。这将使您深入了解正在发生的事情。然后在必要时执行任何清理,并在需要时重新启动应用程序。如果打算长时间运行,这允许您的应用从崩溃中“恢复”。
//handle crashes and kill events
process.on('uncaughtException', function(err) {
//log the message and stack trace
fs.writeFileSync('crash.log', err + "\n" + err.stack);
//do any cleanup like shutting down servers, etc
//relaunch the app (if you want)
app.relaunch({args: []});
app.exit(0);
});
您还可以监听SIGTERM 事件以查看您的应用程序是否被终止,也可以正常关闭服务器、重新启动等。
process.on('SIGTERM', function() {
fs.writeFileSync('shutdown.log', "Received SIGTERM signal");
//do any cleanup like shutting down servers, etc
//relaunch the app (if you want)
app.relaunch({args: []});
app.exit(0);
});
【讨论】:
这可能是由渲染器进程中的几个不同的严重故障(例如内存不足)引起的。要修复它,您必须亲自处理错误。
请参阅https://www.electronjs.org/docs/tutorial/application-debugging#v8-crashes 了解更多详情。具体来说,我建议在启动电子进程之前将 ELECTRON_ENABLE_LOGGING 环境变量设置为 true,这应该会导致错误显示在您启动主进程的控制台中(不是 chrome devtools控制台)。
【讨论】: