A
Andy Turner
I was just pondering about what the Finally in an exception actually
does. Well, I realise that it always gets called regardless of whether
the exception is thrown or not, but isn't that the same as the next
lines of code? What's the difference between these two bits of code:
try
{
WriteFile();
}
catch
{
// Oh dear
Trace.Write ("Data lost");
}
finally
{
// cleanup code
CloseFile();
}
and
try
{
WriteFile();
}
catch
{
// Oh dear
Trace.Write ("Data lost");
}
// Cleanup code
CloseFile();
Cheers
andyt
does. Well, I realise that it always gets called regardless of whether
the exception is thrown or not, but isn't that the same as the next
lines of code? What's the difference between these two bits of code:
try
{
WriteFile();
}
catch
{
// Oh dear
Trace.Write ("Data lost");
}
finally
{
// cleanup code
CloseFile();
}
and
try
{
WriteFile();
}
catch
{
// Oh dear
Trace.Write ("Data lost");
}
// Cleanup code
CloseFile();
Cheers
andyt