try to throw and catch.
The Weird and The Wonderful
1
Posts
1
Posters
0
Views
1
Watching
-
Was troubleshooting some code in C# and came across this: This is not the original code, but just to give an idea of what happens.
try
{
Console.WriteLine("enter try catch");
try
{
Console.WriteLine("enter try finally");
throw new Exception("try-finally exception");
Console.WriteLine("exit try finally");
}
finally
{
Console.WriteLine("finally called");
}
Console.WriteLine("exit try catch");
}
catch (Exception ex)
{
Console.WriteLine("exception: " + ex.Message);
}Output is:
enter try catch enter try finally finally called exception: try-finally exception
The problem was thatexit try catch
was never called. I think the person that has written the code believed that a try-finally has implicit catch.