Reputation: 59302
I read about finalizers at Microsoft and found this interesting sentence:
If Finalize or an override of Finalize throws an exception, and the runtime is not hosted by an application that overrides the default policy, the runtime terminates the process and no active try-finally blocks or finalizers are executed.
I have googled on how to change the default policy, but I'm still confused:
Which policy is Microsoft talking about in the linked article about finalizers? How can I change it? And can I change this policy programmatically for the application which is currently executing?
Note: not that I would like to change that to get the .NET 1.1 finalizer behavior back. I'm just curious. It's always good to know such details when it comes to analyzing someone else's bugs.
Upvotes: 1
Views: 184
Reputation: 239704
When they discuss:
the runtime is not hosted by an application that overrides the default policy
They're talking about an unmanaged application that is using the CLR Hosting Interfaces to host the CLR and allow bits of managed to code to run within it. See e.g. SQL Server with its CLR integration.
They're not talking about a setting that the managed application that is running can change.
See ICLRPolicyManager::SetUnhandledExceptionPolicy
, specifically:
Specifies the behavior of the common language runtime (CLR) when an unhandled exception occurs.
and
By default, the CLR is the final handler for all unhandled exceptions, and its default behavior is to tear down the process. The host can change this behavior by setting the policy value to
eHostDeterminedPolicy
. This value allows the host to implement its own default behavior, as with earlier versions of the CLR.
Upvotes: 3