Why the `AppDomain.UnhandledException` event doesn't happen in my case?

92 Views Asked by At

.Net Framework 4.6.1

Why the AppDomain.UnhandledException event doesn't happen in my case?

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

There are 0 best solutions below