Global application-level exception handler missed

My.net application has a global exception handler by subscribing to the AppDomain.Current.Domain UnhandledException event. On several occasions, I saw that my application crashes, but this global exception handler never hits. Not sure if his help, but the application does some COM interactions.

I understand that as long as I don't have local catch blocks that swallow the exception, this global exception handler should always be hit. Any ideas on what I might lose by calling this handler have never been called?

+4
c # exception-handling
Mar 13 2018-11-11T00:
source share
4 answers

The CLR does not have all the capabilities to catch every exception that unmanaged code can cause. Typically, an AccessViolationException by the way. He can catch them only when calling unmanaged code from managed code. A scenario that is not supported is unmanaged code that rotates its own thread, and this thread crashes. Not very unlikely when you are working with a COM component.

Since .NET 4.0, the Fatal Execution Engine exception no longer throws an UnhandledException event. The exception was deemed too unpleasant to allow more managed code to run. It. And traditionally, a StackOverflowException throws an immediate interrupt.

You can diagnose this a bit from the ExitCode process. It contains an exception code for the exception that terminated the process. 0x8013yyyy is an exception caused by managed code. 0xc0000005 - access violation. Etcetera. You can use adplus, available from debug download to boot Windows, to capture the minidump process. Since this is likely to be caused by the COM component, working with the seller is likely to be important in resolving this issue.

+1
Mar 13 '11 at 19:12
source share

Is this the cause of your problem?

AppDomain.CurrentDomain.UnhandledException does not fire without debugging

+3
Mar 13 '11 at 16:44
source share

Since you are doing COM interoperability, I strongly suspect that some unmanaged code was running in a different thread, which caused an unhandled exception. This will cause the application to exit without accessing your raw exception handler. In addition, with .NET 4.0, the policy has become stronger when the application is closed without further notice. Under the following conditions, your application will be shut down without further notice (Environmnt.FailFast).

Pre.NET 4:

  • Stackoververflowexception

.NET 4:

  • Stackoververflowexception
  • AccessViolationException

You can override the behavior in .NET 4 by decorating the method with HandleProcessCorruptedStateExceptionsAttribute or you can add legacyCorruptedStateExceptionsPolicy for your App.config.

If your problem is an uncovered exception in unmanaged code, you can either run the application under the debugger or allow it to crash and collect a memory dump for debugging post mortem. Crash dump debugging is usually done using WindDbg . After you download Windbg, you have adplus (a vbs script located in the Programm Files \ Debugging Tools for Windows section) that you can attach to the running process to trigger a crash dump when the process terminates due to an exception.

adplus -crash -p yourprocessid

Then you have a much better chance of knowing what happens when your process ends. Windows can also be configured to receive a crash dump for you through DrWatson on older versions of Windows (Windows Error Report)

Crash Dump Generation

Tough programmers insist on creating their own dump generation tool, which mainly uses the AEDebug registry key . When this key has a value that points to an existing executable, it is called when the application crashes, which can, for example, show the Visual Studio Debugger Chooser dialog or it can cause dump generation for your process.

Suspended Threads

It is often overlooked when you create an emergency dump with an external tool (it is better to rely on external tools, since you do not know how bad your process is damaged, and if it goes out of memory, you are already in a bad state of the situation) that you should suspend all threads from the crashed process before you take a dump. When you take a large full memory dump, it may take several minutes depending on the allocated memory of the failed process. During this time, application threads can continue to damage your application state, leaving you with a dump that contains the inconsistent state of the process that changed during the dump.

+1
Mar 13 2018-11-11T00:
source share

This will happen if your handler throws an exception.

This will also happen if you call Environment.FailFast or if you Abort UI thread.

0
Mar 13 '11 at 16:41
source share



All Articles