日期:2014-05-18  浏览次数:20620 次

winform中是否存在类似全局处理异常的设施?
我们知道asp.net有个Global.asax,其中Appliction_Error事件方法,可以对应用程序级的异常进行处理。不知道winform中有吗?在哪里?谢谢~

------解决方案--------------------
// 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 +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
------解决方案--------------------
项目右击属性,点击【查看应用程序时间】按钮,找到MyApplication的UnhandledException事件就是你要的了。
------解决方案--------------------
C# code
 Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);

------解决方案--------------------
楼主看2楼
------解决方案--------------------
2楼正解。