WinFrom Exception Handler

 1 [STAThread]
2 static void Main()
3 {
4 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
5 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
6 Application.EnableVisualStyles();
7 Application.SetCompatibleTextRenderingDefault(false);
8 Application.Run(new Form1());
9 }
10 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
11 {
12 MessageBox.Show("抱歉,您的操作没有能够完成,请再试一次或者联系软件提供商");
13 LogUnhandledException(e.ExceptionObject);
14 }
15 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
16 {
17 MessageBox.Show("抱歉,您的操作没有能够完成,请再试一次或者联系软件提供商");
18 LogUnhandledException(e.Exception);
19 }
20 static void LogUnhandledException(object exceptionobj)
21 { //Log the exception here or report it to developer }
22 }

 

posted on 2012-04-02 00:35  笑东风  阅读(255)  评论(0编辑  收藏  举报

导航