publicstaticvoidMain(string[] args)
{
// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException+= new
ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
// Set the unhandled exception mode to force all Windows Forms
// errors to go through our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException+=
newUnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
// Runs the application.
Application.Run(newErrorHandlerForm());
}
MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx