问题
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