程序结构如下
public A
{
public Start()
{
Thread.Start(B);
}
B()
{
throw new Exception();
}
}
public Test
{
public static void Main()
{
A a=new A();
a.Start();
}
}想在main中处理B抛出来的异常,该怎么做?
请大家不吝赐教。
public A
{
public Start()
{
Thread.Start(B);
}
B()
{
throw new Exception();
}
}
public Test
{
public static void Main()
{
A a=new A();
a.Start();
}
}想在main中处理B抛出来的异常,该怎么做?
请大家不吝赐教。
解决方案 »
- .net调用delphi的dll,知道的兄弟支个招,不胜感激
- 已知三个点的坐标,求夹角
- ASP.NET C# 怎么自动生成不重复序列号?字母和数字组成
- split的用法,在线等,很简单
- 第三方控件中gridcontrol的问题
- 【菜鸟提问】作个程序,要安装在PDA上,在PDA上操作时能影响PC的SQL2000数据库,请问,这个数据库连接该怎么写啊?顶者有分
- 求大侠们帮帮忙,给个思路,给个活口
- winform中如何让“正在加载”的界面保持在前面啊?
- 关于文本编码又有问题了,高手回答
- 用c#做一个画图工具画直线要带缓冲区是什么意思啊
- 请推荐一个带socket重连的c#程序
- 关于TCP的问题.在线等
{
public static void Main()
{
try
{
A a=new A();
a.Start();
}
catch
{
// 处理异常
}
}
}
Console程序,大概可以用AppDomain.UnhandledException 事件来处理。
using System.Security.Permissions;public class Test { [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Example()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : " + e.Message);
} throw new Exception("2"); // Output:
// Catch clause caught : 1
// MyHandler caught : 2
} static void MyHandler(object sender, UnhandledExceptionEventArgs args) {
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
} public static void Main() {
Example();
}
}
线程中的方法可以
异步执行的线程,winfrom中可以用backgroundworker来搞
Thread th = new Thread(new ThreadStart(DoSplash)); th.Start(); Thread.Sleep(5000); try
{
th.Abort();//引发异常
}
catch (ThreadAbortException)
{
//处理异常
} Thread.Sleep(1000);
{
EventWaitHandle whException;
public Start()
{
whException=new AutoResetEvent(false);
Thread.Start(B);
whException.WaitOne();
throw new Exception();
}
B()
{
whException.Set();
}
}
public Test
{
public static void Main()
{
try
{
A a=new A();
a.Start();
}
catch
{
}
}
}