我使用的示例代码是this MSDN article。.NET未处理的异常
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : {0} \n", e.Message);
}
throw new Exception("2");
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
}
该处理程序捕获未处理的异常。但是,在处理程序运行后,未处理的异常2仍然显示。在调试模式下,在发布模式下以及是否直接启动.exe。
我想压制第二个异常,所以未处理的异常处理程序可以终止/重新启动应用程序。我记得使用VB.NET在.NET 3中工作。
请将代码发布在您的帖子中。链接到代码很难遵循和回复。 – Hank
你应该更努力地寻找模式。如果'try catch'有助于例外#1,那么猜猜对于例外#2 ...会有什么帮助? –