Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Global Exception Handler in WinForms

Posted by Paul on October 12, 2010


This is a small code snippet to set the global exception handler in Windows Forms application.

Setting a global exception handler can help us in logging the exceptions to a common file, show them to the user in a friendly way or email to the moderator.

// Place the code inside Program.cs, before Application.Run

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

 

public static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
    // Process the e.Exception
    MessageBox.Show("I got the exception!");
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s