string foo;
try
{
foo = "test"; // yeah, i know ...
}
catch // yeah, i know this one too :)
{
foo = null;
}
finally
{
Console.WriteLine(foo); // argh ... @#!
}
Console.WriteLine(foo); // but nothing to complain about here
Besides it’s not BP (catching-routing) – but this is the best isolation I can get.
But I get nice waves telling me “danger, danger – might be uninitialized”.
How comes?
Edit:
Please do not suggest “Simply put a string foo = string.Empty; at the ‘declaration'”. I’d like to declare it, but just do the assignment on time!
Some background from the C# specification (5.3.3.14):
Edit Try-Catch-Finally(5.3.3.15):
I just thought of an example that shows the problem better: