Re: Terminating program in ProcessWndProcException

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 08/28/04


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



Relevant Pages

  • Re: Custom Service Terminates Unexpectedly
    ... The service is a .Net 2.0 service and handles all exceptions. ... Event log under Service Control Manager, ... terminate, it was right in the middle of an XSLT transform call. ... and run sc query against the service. ...
    (microsoft.public.windows.server.general)
  • Re: Custom Service Terminates Unexpectedly
    ... If the service can't handle any abnormal conditions (eg exceptions) then it may be impossible to know. ... Event log under Service Control Manager, ... It appears that some external event caused the service to terminate in this ... a utility that will log the sc query result to a log file if it happens again. ...
    (microsoft.public.windows.server.general)
  • Re: AfxBeginThread on each user action X or re-use same thread (w
    ... > SEs to C++ typed exceptions. ... DWORD exitCode; ... MyFunction currently doesn't throw, it could only be dead w/ process still ... running when _se_translator_function, or terminate is added. ...
    (microsoft.public.vc.language)
  • Re: ApplicationException unhandled by user code
    ... any unhandled exceptions thrown by your application so that your ... program doesn't terminate or just so that you can handle the errors ... public void ApplicationThreadException(object sender, ... That should let you catch all your exceptions, and in .Net 1.1, it ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: error handling
    ... >> Lisa Pearlson wrote: ... >>> Imagine I have a socket read function.. ... >>> exit 1 ... > exceptions to return data yet allow additional info.. ...
    (comp.lang.tcl)