(Questo sembra molto simile a C# UnhandledException from another thread keeps looping, ma non sto cercando di intercettare l'eccezione qui, basta avere la possibilità di registrare qualcosa)Perché Visual Studio looping durante il debug eventi UnhandledException
ho un po 'molto semplice codice C# che imposta un gestore di eventi UnhandledException, quindi genera un'eccezione:
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");
}
}
Si comporta come mi aspetto dalla console:
Unhandled exception: Bleurgh
Unhandled Exception: System.AccessViolationException: Bleurgh
at UnhandledExceptions.Program.Main(String[] args) in c:\code\sandbox\UnhandledExceptions\UnhandledExceptions\Program.cs:line 20
Ma quando provo a eseguirne il debug in Visual Studio, entra in un loop, entra nel gestore eventi e poi si ritira per rilanciare l'eccezione.
La stessa cosa accade quando esprimo il gestore come un metodo statico distinto.
Qualche idea cosa sta succedendo?
Questo è in Visual Studio 2010. EDIT: e .NET 4.
Possibili duplicati: [prima] (http://stackoverflow.com/q/11469826/395718), [secondo] (http://stackoverflow.com/q/1536954/395718), [terzo] (http: //stackoverflow.com/q/164433/395718). – Dialecticus