Changing the Default Unhandled Exception Dialog

Hi Everyone,

Is it possible for me to customize the default dialog that pops up when .NET encounters an unhandled exception

Thank you.



Answer this question

Changing the Default Unhandled Exception Dialog

  • Revanger

    I spoke too soon..Your answer seems partially right -- probably I am missing something obvious since I'm new to .NET.

    The approach you described allowed me to add a new UnhandledExcepionEventHandler that responds to uncaught exceptions but I was unable to un-hook the default handler that displays the dialog window. So, basically, there were two handlers in place.

    Because AppDomain.CurrentDomain.UnhandledException is an event, I am only able to add handlers to it or remove handlers from it. The problem is that there is no way to remove the default handler, as far as I can see.


  • PhillipWhelan

    Definitely not multiple app domains. Just a single app domain.
  • Ivan B

    THANKS!!
  • JeremyPalmer

    Yes, quite easily. Just hook up to the AppDomain.CurrentDomain.UnhandledException event.

  • Mark Wienzek

    I'm sorry to be so dense about this. This is a C# Console app. I don't know if that matters.

    What is the "e" object The only "ExitApplication" property I can find is for UnhandledExceptionEventArgs class which is in the Microsoft.VisualBasic.ApplicationServices namespace. Is there something equivaluent for C# The UnhandledExceptionEventArgs class in C# does not seem to expose that property.

    Why would the VB class expose it but not the C# Again, I'm sorry for this question if it is too basic.

    Thanks very much.


  • SoftAdmin

    You also may want to look at hooking onto the Application.ThreadException event if you are doing Windows Forms development.

  • ETA76

    You'll want to have a read through the following:
    The default behaviour changed between .NET Framework 1.X and 2.0. What version of the Framework are you running your application on An unhandled exception means that your AppDomain (and hence your application) is going to get torn down. If you're running in the default domain (i.e. haven't created any child domains), I don't believe there is a way to turn off the default message. Your best bet is to not let any unhandled exceptions escape by putting a try/catch around all code in your Main method and any methods for alternate threads (typically used with ThreadStart delegates).


  • lxwSniper

    Set e.ExitApplication to false.

  • Igor Sukhov

    No, it was me being stupid. Just hooking the AppDomain.UnhandledException should stop the default system exception dialog box coming up for that AppDomain. Is it possible you're running more than one AppDomain

  • Changing the Default Unhandled Exception Dialog