Delphi Error handling : Raise vs Exit on try...except...end

Viewed 5578

Is it safe to call Exit on try except? Or should I call raise instead?

I tried both example below and at raise example, the trace went through Delphi's internal library code. While exit just exit the procedure and nothing more.

I read that it's better to preserve application stack or queue or something like that. Will calling exit will break that stack?

Example 1 (raise)

SDDatabase1.StartTransaction;
Try
  SDQuery1.ApplyUpdates;
  SDDatabase1.Commit;
  SDQuery1.CommitUpdates;
Except
  SDDatabase1.Rollback;
  SDQuery1.RollbackUpdates;
  raise;
End;
..............//other codes I don't want to execute

Example 2 (exit)

SDDatabase1.StartTransaction;
Try
  SDQuery1.ApplyUpdates;
  SDDatabase1.Commit;
  SDQuery1.CommitUpdates;
Except
  SDDatabase1.Rollback;
  SDQuery1.RollbackUpdates;
  MessageDlg('Save Failed because: '+E.Message, mtError, [mbOK], 0);
  exit;
end;
..............//other codes I don't want to execute
2 Answers
Related