I wrote a simple program to test the theory that the finally block will always be executed no matter what. But what I see from the pgm below is that the control never enters an external final block.
I tried to make F5 as well as Ctrl-F5 in Visual Studio, and this is the same result.
Can someone explain why I see this behavior?
The output in the console window:
internal catch
internal finally
external catch
raw execution:
.. and then the application crashes
public class Program
{
static void Main()
{
try
{
try
{
string s = null;
s.ToString();
}
catch
{
Console.WriteLine("inner catch");
throw;
}
finally
{
Console.WriteLine("inner finally");
}
return;
}
catch
{
Console.WriteLine("outer catch");
throw;
}
finally
{
Console.WriteLine("outer finally");
}
}
}
source
share