【发布时间】:2013-12-29 07:44:01
【问题描述】:
(这看起来与C# UnhandledException from another thread keeps looping 非常相似,但我不想在这里捕获异常,只是有机会记录一些东西)
我有一些非常简单的 C# 代码,用于设置 UnhandledException 事件处理程序,然后引发异常:
class Program
{
static void Main(string[] args)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
//currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
currentDomain.UnhandledException += (sender, eventArgs) =>
{
var exception = (Exception) eventArgs.ExceptionObject;
Console.WriteLine("Unhandled exception: " + exception.Message);
};
throw new AccessViolationException("Bleurgh");
}
}
它的行为符合我对控制台的期望:
Unhandled exception: Bleurgh
Unhandled Exception: System.AccessViolationException: Bleurgh
at UnhandledExceptions.Program.Main(String[] args) in c:\code\sandbox\UnhandledExceptions\UnhandledExceptions\Program.cs:line 20
但是当我尝试在 Visual Studio 中调试它时,它会进入一个循环,进入事件处理程序,然后退出以重新引发异常。
当我将处理程序表示为不同的静态方法时,也会发生同样的事情。
有什么想法吗?
这是在 Visual Studio 2010 中。编辑:和 .NET 4。
【问题讨论】:
标签: c# visual-studio-2010 c#-4.0 unhandled-exception