Electron dying without any information, what now?

谁说胖子不能爱 提交于 2019-12-06 12:32:53

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 + "\n" + err.stack);

  //do any cleanup like shutting down servers, etc

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

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);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!