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()之前添加
總結
以上是生活随笔為你收集整理的winform中捕获程序未处理的所有异常的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式之策略模式(strategy)-
- 下一篇: SDM管理路由器要进行的相应配置