C#捕获winform程序所有未处理的异常
C#全局捕获winform程序所有未处理的异常
1、命名空间引用:
using System.Text;
2、处理方法:
private static void AppThreadException(object source, System.Threading.ThreadExceptionEventArgs e) { string errorMsg = string.Format("未处理异常: \n{0}\n", e.Exception.Message); errorMsg += Environment.NewLine; DialogResult result = MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop); //如果点击“中止”则退出程序 if (result == DialogResult.Abort) { Application.Exit(); } }
3、Main方法添加:
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(AppThreadException);
在Application.Run()之前添加
来源:http://www.cnblogs.com/tuyile006/archive/2007/10/06/915367.html
加支付宝好友偷能量挖...