CRITICAL
Rule Definition
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. This behavior ensures process integrity if the finalizer cannot free or destroy resources.
Remediation
Do not throw exceptions in destructors
Violation Code Sample
class MyClass
{
~MyClass()
{
throw new NotImplementedException();
}
}
Fixed Code Sample
class MyClass
{
~MyClass()
{
// no throw
}
}
Reference
https://docs.microsoft.com/en-us/dotnet/api/system.object.finalize?redirectedfrom=MSDN&view=netcore-3.1#System_Object_Finalize
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.