Are there any practical difference between the two coding patterns in Delphi:
Version 1
try
try
{Do something}
finally
{Do tidy up}
end
except
{Handle exception}
end;
Version 2
try
try
{Do something}
except
{Handle exception}
end
finally
{Do tidy up}
end;
There are two differences:
Usually you aren't concerned about finally blocks that raise. You simply don't expect that to happen and if it does, something is probably very broken.
So the difference that counts is whether the finally runs before the exception handler, or vice versa. Sometimes it doesn't matter, but it often does make a difference.
When you use try..except
below lines executed.
Resource := TAbstractResource.Create;
try
Resource.DoSomeThing;
except
On E:Exception Do
HandleException(E);
end;
FreeAndNil(Resource);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With