Re: Terminating program in ProcessWndProcException
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 08/28/04
- Next message: Alexander Grigoriev: "Re: Detecting the mouse speed"
- Previous message: Bredal Jensen: "Should i leran delphi instead?"
- In reply to: Martin Aupperle: "Terminating program in ProcessWndProcException"
- Next in thread: Martin Aupperle: "Re: Terminating program in ProcessWndProcException"
- Reply: Martin Aupperle: "Re: Terminating program in ProcessWndProcException"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 28 Aug 2004 12:46:05 -0400
Philosophically, NO program should terminate except by user directive. When I get problems
like this, I simply enter a mode in which most of the menu items are disabled. One of the
few that is still active is Program>Exit, and I usually have a few diagnostic menu items
that either become enabled or appear magically.
Do not call _exit. Do not call _abort. The problem with all such "recovery" mechanisms is
that besides doing more harm than good, they aren't defined for Windows apps.
It is an old Unix console-process mindset that even considers the possibility that a
program should terminate itself. The dbx debugger was noted for things like if it got
unhappy with the symbol table format, calling exit(), thus terminating the debug session
without warning. One of our best programmers spent six months removing all but one exit()
call from this program, and that was the one that was used when the "quit" command was
typed.
Posting WM_QUIT won't help, because ;you probably don't have a message loop running at
that point.
A more serious question is where are these exceptions coming from? If they are exceptions
you are throwing, that's fine. But if they are exceptions being thrown by the runtime in
some way, they should be fixed.
My exception loop was something like
int MYApp::Run()
{
while(true)
{ /* main loop */
try
{
return CWinApp::Run();
}
catch(...specific exception...)
{
}
catch(...other exception....)
{
}
catch(...)
{
}
} /* main loop */
}
I then set the appropriate error state conditions, in some cases reported the nature of
the error, and set flags to indicate what recovery was required.
There is nothing more confusing to a user than having a program spontaneously exit. There
is nothing harder for tech support to deal with than a program that merely exits.
By continuing to run, I was able to add diagnostics and reporting mechanisms that would
allow tech support todiagnose the problem. This was important, because the libraries we
used would throw random exceptions. Putting an exception frame at every call was too hard
(hundreds of calls). Once I started catching exceptions like this, we could target our
handlers to do better recovery in key places.
joe
On Sat, 28 Aug 2004 06:03:48 GMT, XXXMartin.Aupperle@PrimaProgrammXXX.de (Martin Aupperle)
wrote:
>Hello,
>
>I catch some of my exceptions in MyApp::ProcessWndProcException. THat
>works fine as long as I want to continue the program. Some exceptions
>however denote fatal conditions, and the program shoult terminate
>immediately.
>
>I tried exit, _exit, and abort, but all give me an access violation.
>What is the right way to terminate?
>
>Posting a WM_QUIT to my MainFrame is not really an option because all
>sorts of processing can take place that I don't want. For example, all
>parts of the program are notified to make them store their state,
>store unsaved data, etc.
>
>Martin
>------------------------------------------------
>Martin Aupperle
>------------------------------------------------
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Alexander Grigoriev: "Re: Detecting the mouse speed"
- Previous message: Bredal Jensen: "Should i leran delphi instead?"
- In reply to: Martin Aupperle: "Terminating program in ProcessWndProcException"
- Next in thread: Martin Aupperle: "Re: Terminating program in ProcessWndProcException"
- Reply: Martin Aupperle: "Re: Terminating program in ProcessWndProcException"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|