because after "except on do" construct I can't put begin and end; and it only allows for 1 statement to be executed.
try
SList.LoadFromFile(Filename);
except on E:EFOpenError do
// doing other things here maybe 🤔
Halt(1);
end;
Except on e:efopenerror do begin ... end; on e:exception do begin ... end; end;
except-end is equivalent to begin-end, so simply: try SList.LoadFromFile(Filename); except functionA(); functionB(arg1, arg2); if(something) then begin bla bla blah end else begin blah blah end; Halt(1); end;
I do not advise writing code inside the exception section
that's what the except section is for ;)
it is designed to handle errors in the first place. And redundant and large code inside the exception can throw a new exception that will no longer be caught.
handling errors can require more than a single line of code.
Result := False; - enough
some times yes, other times no
"And redundant and large code inside the exception can throw a new exception that will no longer be caught."
this is interesting point. I do use nested try-except often, in order to suppress exception messages.
this is not a very good code
how can you know if you haven't seen the code ;)
"nested try-except"
Обсуждают сегодня