I know it sounds like an old stupid question but I searched all over the internet and I still don't understand one thing. I understand that try-finally will run the finally code before stopping for error (or don't stopping when no exceptioned was raised) and that try-except will run the except code when exception is raised. But what I still don't understand is the point of try-except within try-finally statements. I'll write an example
What I always do is something like this:
a:=x.Create;
try
a.DoRiskyStuff;
except
ShowMessage('Error!');
end;
a.free;
I have never in a years used a finally clause because I always handle the errors and I never understood what is the point to use them both nested together. What's bad about my solution? Why in examples it's common to use something like this:
a:=x.Create;
try
try
a.DoRiskyStuff;
except
ShowMessage('Error!');
end;
finally
a.free;
end;
What's the difference? Why should somebody use a finally clause when all cleanup can be done after the try-except?
Thank you very much for any asnwers!
Edit: I changed the create lines so some of you want bash me for it ;)