When subscribed to events on AppDomain.CurrentDomain.UnhandledException
what criteria causes the UnhandledExceptionEventArgs
IsTerminating
flag to be true? I.e. what causes an exception to be considered fatal?
Is it the case that by default all unhandled exceptions will be fatal unless configured otherwise?
This property is always true. It used to be possible to be false, way back in the .NET 1.x days. That version allowed a thread to die on an unhandled exception without that having the entire process terminate. That just didn't work out well, programmers didn't implement the event handler (or didn't know how to properly handle the exception from the event, who does) so threads just died without any notice whatsoever. Almost impossible to not have this cause difficult to diagnose program failure.
Microsoft changed the default behavior in .NET 2.0, an unhandled exception terminates the program. Technically it is still possible to override this behavior, a custom CLR host can keep the process alive by implementing the IHostPolicyManager interface. And the default host supports the <legacyUnhandledExceptionPolicy>
config element. Don't use it, that way lies dragons.
No, unhandled exceptions from managed threads spawned by another application will have IsTerminating equal to false, since it'll kill the thread but not the overall application. That's the only time I've ever seen IsTerminating false in this situation, and the MSDN page says that this is the main use-case too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With