.NET 程序中的異常處理

 

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

http://stackoverflow.com/questions/2014562/whats-the-difference-between-application-threadexception-and-appdomain-currentd

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章