.Net Framework: Finally block is not being called when the exception is not being caught [duplicate]

大城市里の小女人 提交于 2021-02-20 19:07:32

问题


A simple console application, in Visual Studio 2019, .Net Framework 4.7, Windows:

static void Main(string[] args)
{
    try
    {
         Console.WriteLine("In try");
         throw new IndexOutOfRangeException();
    }
    finally
    {        *// Surprisingly this part is not being executed.*
         Console.WriteLine("In finally");
         Console.ReadLine();
    }                       
}

I was sure that finally block is being called in case of NO Exception, and in case of YES Exception. I've read in the docs:

However, if the exception is unhandled, execution of the finally block is dependent on how the exception unwind operation is triggered. That, in turn, is dependent on how your computer is set up.

Link Well, I'm confused. Do I need to to something with this "unwind operation" in order finally will be called in case of unhandled exceptions?

来源:https://stackoverflow.com/questions/65069918/net-framework-finally-block-is-not-being-called-when-the-exception-is-not-bein

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!