Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what happened in .NET if exception occurred in finalizer method (~Method)

Tags:

c#

.net

exception

I'm curious, what really happens inside .NET, if exception happened in finalizer method during garbage collection procedure. Did the logic different for heap and LOH? Could anyone provide detailed description?

like image 615
Ph0en1x Avatar asked Oct 03 '22 16:10

Ph0en1x


1 Answers

Nothing much special. The CLR will detect the exception and terminate the program.

Do note that the article linked by @kmatyaszek is grossly outdated. Swallowing exceptions in finalizers and worker threads was a .NET 1.x feature that caused a lot of misery. It is pretty difficult to diagnose the reason a program stops behaving properly when this happens. .NET 2.0 put an end to it, the default policy is to always terminate the program. Technically that can be overridden by a custom CLR host and the <legacyUnhandledExceptionPolicy> element in the app.exe.config file. Don't use it unless you like misery.

like image 119
Hans Passant Avatar answered Oct 13 '22 09:10

Hans Passant