Self restarting application on crash



  • I want my application to self restart if it crashes. I have a couple of ideas of how to do this, but maybe you could recommend me a better one. Idea #1: Create a console application (hide it), which will start my GUI application, and if my GUI crashes it will create a new GUI application. Idea #2 By using try, catch, throw therefore if I will get an unknown error which I won't be able to handle it will create a new instance of the GUI application and will close the current one (the one that crashed). Is this are good ideas or maybe you can recommend me smth better?



  • To be honest, your best bet is to make sure your application doesn't crash! It's too easy to get into an infinite loop where your app crashes over and over and gets restarted over and over, and your users aren't going to like that. Are you having problems with your app crashing? Maybe we can help you resolve those instead.



  • @Chris-Hennes Nope no problems with the crashes, but sometimes the app can crash. My app is going to launch other applications and I don't know if the app will crash or not, therefore I want to restart the app if it crashes. I will make smth like a counter so if it will self restart more that say 3 times it will stop doing that.



  • How are you launching the apps you are worried about crashing? Are you using QProcess?



  • @Chris-Hennes That's what I was planning to use



  • Then you can connect to the finished signal and get the return code of the program, which will (generally) tell you if the program crashed.


  • Qt Champions 2016

    @mandruk1331 said in Self restarting application on crash:

    I want my application to self restart if it crashes

    Eh, as mr Hennes said it's best to ensure your application doesn't crash to begin with. Or if it does to track down the actual bug.

    Idea #1: Create a console application (hide it), which will start my GUI application, and if my GUI crashes it will create a new GUI application.

    It's not always easy to "hide it" as it will have a console terminal attached to it. You can in principle use a daemon/service for this, but ... well I'm very suspicious of such behaviour in applications.

    #2 By using try, catch, throw therefore if I will get an unknown error which I won't be able to handle it will create a new instance of the GUI application and will close the current one

    Assuming that your "crashes" are caused by an uncaught exception (thus the runtime terminating the app due to the default OS's exception handler) it could work. But then not all errors are exceptions. If you overrun memory this is no exception, if you divide by zero it's no exception, etc.

    You could attach a SIGTERM/SIGSGV handler in principle, but again I'd be very wary of code that restarts itself while responding to those signals.


Log in to reply