Created
June 4, 2012 13:12
-
-
Save Dynyx/2868283 to your computer and use it in GitHub Desktop.
Unhandled exception handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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