Re: SetUnhandledExceptionFilter

From: Ivan Brugiolo [MSFT] (ivanbrug_at_online.microsoft.com)
Date: 05/25/04


Date: Tue, 25 May 2004 14:45:41 -0700

The only way to prevent at all cost a crash in the applicaiton
is to have code that can be proven all-case correct that runs over there
:-).
If your goal is to NOT crash the application from your code,
then you can do something about, but, per my experience,
you might crash the application with your module on the stack
because of some corruption in the shared state of the application.
Looking at a full dump of Word.exe and/or LotusNotes is the only way
to diagnose the problem. All other solutions are short leged.
They are useful only to the fingerpointing exercise, and not to the
resolution.

As I said in the end of the posting, a correct stack code capture
with StackWalk64 requires full symbols, that are non a cheap commodity
in terms of deployment and disk space.

Let me reinforce the concept that binlde exception filtering is bad in
general.
In the anatomy of an application crash, there are 3 times:
-1- t_corr, when a corruption in the global state happens
(overwriting a heap metadata, unloading a module prematurely, leaking
CritSec)
-2- t_det, where the corruption has a sensible side effect on some code
(for eaxmple, heap metadata is checked in the free and coalasce code path.
Paradoxically, and application that leaks will suffer less from corruptions.
A bad heap metadata will cause an access violation, the access violation is
normally dismissed in some wide exception handler)
-3- t_crash, when the alteration in the global state causes
kernel32!UnhandledExceptionFitler,
or msvcrt!abort, or a generalized application hung to happen.
Even if you can write code that runs at t_det, for example, by installing
exceptions filters
and/or vectored exception handlers, your code may run minutes after t_corr,
and, your stack trace is not that useful in isolation, and it may be useful
only
with a full dump of the process.
Writing correct code in a shared process is a matter
of cooperation of all the entities involved in that process.

It's not bad to install an unhandled exception filter in DllMain because
it's in DllMain.
It's a bad idea to attempt to chain a behavior over other behaviors
with no guarantee of what is the order and the final result for a process
that you don't own.

For code that runs in shared application, and for Microsoft applications,
you can engage (through your company) the ISV portal team to get access
to custumer reported dumps minidump that contains your module.
Or, you can change the error reporting infrastructure to report the dump to
your web site,
or, you can have the dumps to be queued in a central location.

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Werner B. Strydom" <bloudraak@hotmail.com> wrote in message
news:uYU91WpQEHA.4000@TK2MSFTNGP10.phx.gbl...
> Hi Ivan,
>
> Thanks for the reply. Here's some remarks:
>
> I'm told not to crash the application and prevent that at all cost. I'm
also
> told, prevention is better than cure. So, if I have an access violation,
> stack corruption or something like that somewhere in my code, its best to
> know about it quickly. ;) Looking at a dump of Microsoft Word or Lotus
Notes
> is a time consuming and expensive task.
>
> Stack dumps is a last resort. For that to happen, 80MB of symbols needs to
> be installed. Remote debugging even a later resort [many firewalls and
> companies don't allow that anyways].  We do the whole try/catch spiel.
> However catch(...) doesn't tell me much as to where the access violation
> happened, or that an access violation even happened (could be a third
party
> exception class).
>
> We write tests for everything except the coffee machine. For standalone
> tests, the test harness installs various callbacks (_set_se_translator,
> _set_unexpected, _set_new_handler etc.) which throws C++ exceptions.
> Failures are reported (rather than crashing the process), and we have
enough
> information (from a stack trace, perhaps) to fix it quickly. What about
dlls
> loaded by Microsoft Word, Outlook, Lotus Notes or GroupWise? For extension
> dlls I'm learning here that its a bad idea to install an exception handler
> in DllMain, because its unreliable, it may effect other third party code
and
> may be totally hidden from you until its too late. Its a shame.
>
> Regards
> Werner
>
>
>
>


Relevant Pages

  • Re: Crash without dump file
    ... Compile it in debug mode and deploy the .pdb files. ... There were neither popup windows signaling it nor dump file created. ... Exception ex = e.ExceptionObject as Exception; ... PC use unmanaged code to handle serial COM ports and never crash! ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ADAM crashing
    ... shutting itself down when it gets an address exception. ... > is writing the crash dump to, the path should be up top in that UI if I ... >>> rights. ...
    (microsoft.public.windows.server.active_directory)
  • Re: Crash without dump file
    ... Enumerate over the exception object in your UE handler get the exception ... message and stacktrace and dump the contents to a log file or the eventlog. ... | 9 PC use unmanaged code to handle serial COM ports and never crash! ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: No symbols loaded
    ... "Unhandled exception at 0x8f345690 in vsdv.exe: ... Access violation ... Why the "Break" doesn't lead me to the crash line? ... against the list of modules in Modules window to see if that's the case. ...
    (microsoft.public.vc.language)
  • Re: change font size?
    ... [Please do not mail me a copy of your followup] ... By "crash", I'm assuming you mean something like an access violation ... exception. ...
    (microsoft.public.win32.programmer.directx.graphics)