首页 技术 正文
技术 2022年11月12日
0 收藏 483 点赞 3,199 浏览 861 个字

一、在program.cs处完善成如下,但是这样后只能抛出主线程(UI)的错误,所以请看第二步

/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//全局异常捕捉
Application.ThreadException += Application_ThreadException; //UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //多线程异常

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}

//UI线程异常
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
WinformException.FrmBugReport.ShowBug(e.Exception);
}

//多线程异常
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
WinformException.FrmBugReport.ShowBug((Exception)e.ExceptionObject);
}

二、将其他线程异常抛掷到主线程

//
Thread t = new Thread((ThreadStart)delegate
{
try
{
throw new Exception(“非窗体线程异常”);
}
catch (Exception ex)
{
this.BeginInvoke((Action)delegate
{
throw ex;
});
}
});
t.Start();

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844