C# language annoyance of the day
Sunday, May 30th, 2004This actually applies to all the C-derived languages.
If I have code like this:
File f = File.OpenText(“MyFile.txt”);
f.ReadLine();
And I want to handle the case where the file is not found:
try
{
File f = File.OpenText(“MyFile.txt”);
} catch (FileNotFoundException ex)
{
Console.WriteLine(“File not found.”);
return false;
}
f.ReadLine();
The problem with this is that the scope of f ends at the end of the [...]