Many things have be mentioned for nested exception handling in Delphi or fpc. Something like this for example. My question, that maybe solves the need for nested try... blocks, is if there is an actual difference between the following 2 versions of code, I don't see any except if an undefined behavior or something occurs after expect or finally...
try
StrToInt('AA');
finally
writeln('I absolutely need this');
end;
writeln('and this');
and...
try
StrToInt('AA');
except
end;
writeln('I absolutely need this');
writeln('and this');
Yes there is a difference. Huge one.
If there is no exception in
tryblock then both versions will execute all code, but if there is an exception behavior differs.In first version of your code, anything after
finallyblock will not be executed and exception will be propagated to the next level.In second version exception will be handled by
exceptblock and code following will continue with normal execution.In linked question you have nested exception blocks, and that situation will behave differently than above one, in the way it was explained in answers to that question.
Documentation: Delphi Exceptions