Skip to content

Instantly share code, notes, and snippets.

@Dynyx
Created June 4, 2012 13:12
Show Gist options
  • Save Dynyx/2868283 to your computer and use it in GitHub Desktop.
Save Dynyx/2868283 to your computer and use it in GitHub Desktop.
Unhandled exception handling
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.Run(new Form1());
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception");
// here you can log the exception ...
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).Message, "Unhandled UI Exception");
// here you can log the exception ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment