电子在没有任何信息的情况下死亡,现在怎么办? [英] Electron dying without any information, what now?

查看:15
本文介绍了电子在没有任何信息的情况下死亡,现在怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建的应用程序,当我编译它以使用电子生成器打包它时,时不时地死掉,显示一个空白屏幕和一个断开连接的开发工具:

The app I'm building, when I compile it for distribution packing it with electron-builder, every now and then, dies, showing a blank screen and a disconnected devtools:

任何想法发生了什么或如何开始弄清楚这里发生了什么?

Any ideas what's going on or how to start figuring out what's happening here?

推荐答案

监听 uncaughtException 事件并记录您遇到的任何错误.这将使您深入了解正在发生的事情.然后在必要时执行任何清理,并在需要时重新启动应用程序.如果打算长时间运行,这允许您的应用从崩溃中恢复".

Listen for the uncaughtException event and log any error that you get. This will give you insight into what is happening. Then perform any cleanup if necessary and relaunch the app if desired. This allows your app to "recover" from crashes if it is intended to be long-running.

//handle crashes and kill events
process.on('uncaughtException', function(err) {
  //log the message and stack trace
  fs.writeFileSync('crash.log', err + "
" + err.stack);

  //do any cleanup like shutting down servers, etc

  //relaunch the app (if you want)
  app.relaunch({args: []});
  app.exit(0);
});

您还可以监听 SIGTERM 事件以查看您的应用程序是否被终止,也可以正常关闭服务器、重新启动等.

You can also listen to the SIGTERM event to see if your application is being killed off, and also gracefully shutdown servers, restart, etc.

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);
});

这篇关于电子在没有任何信息的情况下死亡,现在怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆