为什么`AppDomain.UnhandledException`事件在我的情况下不会发生?

时间:2017-01-08 10:59:41

标签: c# .net appdomain unhandled-exception

.Net Framework 4.6.1

为什么AppDomain.UnhandledException事件在我的情况下不会发生?

class MyClass {

    static void Main(string[] args) {

        AppDomain.CurrentDomain.UnhandledException +=
            UnhandledExceptionHandling;

        int a = 2;
        int b = 0;

        // Here I expected a jump to 
        // UnhandledExceptionHandling...
        // But I get the DivideByZeroException exception
        // instead of.
        int c = a / b; 
    }

    private static void UnhandledExceptionHandling(
        Object sender, UnhandledExceptionEventArgs e) {

        // But I don't get here...
        Console.WriteLine(((Exception)
            e.ExceptionObject).Message);
    }
}

0 个答案:

没有答案