Friday, April 4, 2014

UnhandledExceptionEventHandler for global error handling

The UnhandledExceptionEventHandler can be used to catch unhandled exceptions that have bubbled up to the surface causing the program to crash. This allows you to log the uncaught exception so that the root problem can be debugged. This doesn't try to stop the crash from happening, it just reports it.

In the application loading code (i.e. Main() or the DLL entry point)
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

        public void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
           //Log the error
        }


No comments:

Post a Comment

There was an error in this gadget