捕获未处理的异常

//捕获当前未绑定异常

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 

//捕获线程异常

Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)        

{            

Exception exp = e.Exception;           

//todo:记录异常    

}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)        

{            

Exception exp = (Exception)e.ExceptionObject;            

//todo:记录异常       

}
posted @ 2012-11-14 10:09  『①角硬幣』  阅读(141)  评论(0编辑  收藏  举报