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;

Comments

  1. Nothing wrong with a little context enrichment - if only you don't do it like this and lose the whole call stack :P

    ReplyDelete
  2. I love the "for some reason or another" part -- precision is the order of the day!

    ReplyDelete
  3. Lars Fosdal
    You 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;

    ReplyDelete
  4. 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 ;)

    ReplyDelete
  5. True, Stefan Meisner!  
    on e: exception do Panic;

    ReplyDelete
  6. Lars Fosdal The important thing is adding the ;) at the end!

    ReplyDelete
  7. Honestly, I always add the ; at the end.  
    Too many missing ; errors :)

    ReplyDelete
  8. Stefan Meisner You mean "raise;" not "raise e;" because the last would lead to an access violation.

    ReplyDelete
  9. At least it didn't just eat the exception. (Always the optimist )

    ReplyDelete
  10. Lars Fosdal surely with the new version of Delphi, e.InnerException would contain the original exception (and call stack)?

    ReplyDelete
  11. Nicholas Ring - Honestly, I don't know. Never used it.  I either handle the exception, or I don't.

    ReplyDelete
  12. ShowMessage('something went wrong');

    ReplyDelete
  13. EFunctionalityNotSpecified.Create;

    ReplyDelete
  14. Graeme Geldenhuys Totally agree with you and that is why I use System.sLineBreak

    ReplyDelete

Post a Comment