detecting exceptions in threads
-
Hi all, At the moment my Dialog based program runs 2 threads from inside ...Dlg.cpp. The user interface is updated by the Dialog box, and I am using one for doing all the main functionality, while the other thread prints to a file every minute to let the user know it hasnt crashed. The way it was supposed to work was if the program crashed the printing to the log would stop and a external program would detect this and restart the program. But if(when!) the program throws an exception the dialog saying an exception comes up and the app keeps running its other threads. Wouldnt an unhandled exception stop all the other threads associated with the process, and if not how could i make it do that so i could restart the program? Thanks
-
Hi all, At the moment my Dialog based program runs 2 threads from inside ...Dlg.cpp. The user interface is updated by the Dialog box, and I am using one for doing all the main functionality, while the other thread prints to a file every minute to let the user know it hasnt crashed. The way it was supposed to work was if the program crashed the printing to the log would stop and a external program would detect this and restart the program. But if(when!) the program throws an exception the dialog saying an exception comes up and the app keeps running its other threads. Wouldnt an unhandled exception stop all the other threads associated with the process, and if not how could i make it do that so i could restart the program? Thanks
Ubersnack wrote: Wouldnt an unhandled exception stop all the other threads associated with the process Nope. Exceptions only affect a single thread. My solution would be to not write to a file at all. I would have the program send a message to the other program (use
SendMessage()
to the other program's window) periodically, in response to aWM_TIMER
message. Do this from the same thread as the one that takes input. If there is an exception, the timer handler will not get called, and the message will not get sent. If the other program doesn't receive a message within a certain time period (I would set it to 2-3 times the message period) then it can restart the program. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact" -
Ubersnack wrote: Wouldnt an unhandled exception stop all the other threads associated with the process Nope. Exceptions only affect a single thread. My solution would be to not write to a file at all. I would have the program send a message to the other program (use
SendMessage()
to the other program's window) periodically, in response to aWM_TIMER
message. Do this from the same thread as the one that takes input. If there is an exception, the timer handler will not get called, and the message will not get sent. If the other program doesn't receive a message within a certain time period (I would set it to 2-3 times the message period) then it can restart the program. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"cheers mate :-D
-
Hi all, At the moment my Dialog based program runs 2 threads from inside ...Dlg.cpp. The user interface is updated by the Dialog box, and I am using one for doing all the main functionality, while the other thread prints to a file every minute to let the user know it hasnt crashed. The way it was supposed to work was if the program crashed the printing to the log would stop and a external program would detect this and restart the program. But if(when!) the program throws an exception the dialog saying an exception comes up and the app keeps running its other threads. Wouldnt an unhandled exception stop all the other threads associated with the process, and if not how could i make it do that so i could restart the program? Thanks
The only way for your program to crash from an exception is from an unhanded exception. Unhanded exceptions are bugs! Make sure you catch your exceptions. When an exception occurs; notify the dialog, stop all threads, and restart the threads. There is not need to have a 2nd application watching and restarting. If your application requires a complete restart to get things going again, reorganize your code. It needs to be more object oriented. Hack on! :) Jonathan Craig www.mcw-tech.com