Exception Handler of the Day:
Exception Handler of the Day:
try
...
except
On E:Exception do
begin
raise Exception.Create('Failed to make DB Snapshot for some reason or another.'+CRLF+E.Message);
end;
end;
try
...
except
On E:Exception do
begin
raise Exception.Create('Failed to make DB Snapshot for some reason or another.'+CRLF+E.Message);
end;
end;
Nothing wrong with a little context enrichment - if only you don't do it like this and lose the whole call stack :P
ReplyDeleteI love the "for some reason or another" part -- precision is the order of the day!
ReplyDeleteLars Fosdal
ReplyDeleteYou not only loose the callstack but the chance to handle the specific exception as all are now of the same type: Exception. Probably it would be better to change this to
e.Message := 'foo' + CRLF + e.Message;
raise e;
Well, I was sitting in a truck, 20 feet from a WiFi point today, and watched the still standing truck computer's wireless adapter decide to disconnect from time to time - for some reason or another ;)
ReplyDeleteTrue, Stefan Meisner!
ReplyDeleteon e: exception do Panic;
Lars Fosdal The important thing is adding the ;) at the end!
ReplyDeleteHonestly, I always add the ; at the end.
ReplyDeleteToo many missing ; errors :)
Stefan Meisner You mean "raise;" not "raise e;" because the last would lead to an access violation.
ReplyDeleteAt least it didn't just eat the exception. (Always the optimist )
ReplyDeleteLars Fosdal surely with the new version of Delphi, e.InnerException would contain the original exception (and call stack)?
ReplyDeleteNicholas Ring - Honestly, I don't know. Never used it. I either handle the exception, or I don't.
ReplyDeleteShowMessage('something went wrong');
ReplyDeleteEFunctionalityNotSpecified.Create;
ReplyDeleteGraeme Geldenhuys Totally agree with you and that is why I use System.sLineBreak
ReplyDelete