How does SetUnhandledExceptionFilter work in .NET WinForms applications?

后端 未结 3 718
甜味超标
甜味超标 2020-12-08 23:48

I am working on a project to enhance our production debugging capabilities. Our goal is to reliably produce a minidump on any unhandled exception, whether the exception is

3条回答
  •  没有蜡笔的小新
    2020-12-09 00:18

    If you want your GUI thread exceptions to work just like your-non GUI ones, so that they get handled the same way, you can do this:

    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
    

    Here's the background:

    In a manged GUI app, by default, exceptions that originate in the GUI thread are handled by whatever is assigned to the Application.ThreadException, which you can customize like this:

    Application.ThreadException += 
        new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    

    Exceptions that originate in the other threads are handled by AppDomain.CurrentDomain.UnhandledException, which you can customize like this:

    AppDomain.CurrentDomain.UnhandledException += 
        new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
    

    Assigning to UnHandledException works exactly like calling Win32 SetUnhandledExceptionFilter.

    If you goal is to create minidumps and then use them, you'll need to use Debugging Tools for Windows, sos.dll. You'll need to produce minidumps MiniDumpWithFullMemory.

    And then, even then, you probably won't have everything you might want. System.Diagnostics.StackTrace to get the call managed call stack.

提交回复
热议问题