This is a mirror of official site: http://jasper-net.blogspot.com/

Recovering your application from unhandled exception in .net

| Monday, November 15, 2010
Exception handling is one of the nightmare and the best practice for any programmer. But doesn't matter how good the programmer is, there will be always a chance of unhandled exception daunting the users. .net 2.0+ however has a better option of handling it which is focused on recovering your application on the next start.

AppDomain.UnhandledException is an event which will allow you to handle any unhandled exceptions that would occur anywhere on your application. When you define the delegate for the above said event, it will allow you to write the code to save the current state of the application or do any custom operations so that the crash can be recovered during next recovery. However, if you wish to give user the control of handling the situation, it can be done using a excpetion dialog.

Now lets get into business.

       /// <summary>
       /// The main entry point for the application.
       /// </summary>
       [STAThread]
       static void Main()
       {
           AppDomain.CurrentDomain.UnhandledException +=
               new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
           Application.SetUnhandledExceptionMode(
               UnhandledExceptionMode.CatchException, true);

           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);

Read more: Jebarson's site for Microsoft programmers

Posted via email from .NET Info

0 comments: