It has already been determined here that an empty using block is not an appropriate way to override Dispose()
, but what about the following case?
Is this a legitimate use for an empty using
block?
try
{
using (File.OpenRead(sourceFile)) { }
}
catch (FileNotFoundException)
{
error = "File not found: " + sourceFile;
}
catch (UnauthorizedAccessException)
{
error = "Not authorized to access file: " + sourceFile;
}
catch (Exception e)
{
error = "Error while attempting to read file: " + sourceFile + ".\n\n" + e.Message;
}
if (error != null)
return error;
System.Diagnostics.Process.Start(sourceFile);