开发者

c# finalizer throwing exception?

开发者 https://www.devze.com 2022-12-28 00:33 出处:网络
Quote from MSDN: If Finalize or an override of Finalize throws an exce开发者_运维问答ption, the runtime ignores the exception, terminates that Finalize method, and continues the finalization process.

Quote from MSDN:

If Finalize or an override of Finalize throws an exce开发者_运维问答ption, the runtime ignores the exception, terminates that Finalize method, and continues the finalization process.

Yet if I have:

~Person()
{
throw new Exception("meh");
}

then it results in a runtime exception?

p.s. I know that this should never happen, however I'm just curious around this behaviour. One of our clients had an empty try catch around all of their finalizers.. it didn't even log when things went wrong or reserect the object :/


Linking the source of your quote is important. I have to assume it talks about an old version of .NET, perhaps version 1.x. It tried to be "tolerant" of unhandled exceptions, swallowing them without a squeak. That did not work out well, chunks of code silently failing is extraordinarily hard to debug.

The .NET 2.0 version put an end to that, the default CLR host terminates the app for any unhandled exception. An exception in a finalizer is fatal.


I'm curious as to what happens in xamarin since i've seen this happen in production and the android app did not crash, it is possible that a lock occurred on the finalizer thread and the app ran sub-par until restart.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号