Here is the setup:
1. Customer table has a field with a foreign key constraint to a Definitions table.
2. The Definitions table has a Master-Detail relationship to a Lines table, and the Lines table has a Master-Detail relationship to a Chunks table.
3. The Customer table has a BeforeDelete event which deletes the detail records from the Lines table (in reverse order) and the Lines table has a BeforeDelete event that deletes the detail records from the Chunks table.
4. I have a transaction set up to allow for rollback when an error happens.
Now Deleting a record from the definition table that exists in the customer table field throws the integrity constraint error. That is great!
However when I put a try-except block around the table delete call, none of the defined exceptions are catching the error. I only get the awful Delphi generic exception dialog and the irritating error clunk sound.
I am wanting to catch the error so users don't see this useless message:
ORA-02091: transaction rollled back
ORA-02092: integrity constraint (ALPS.CUSTOMER_FK18) violated - child record found.
but instead see somthing like:
This definition is in use and cannot be deleted.
I have tried the following, none of which show the MessageDlg.
Code: Select all
procedure TfrmExportEdit.btnDeleteClick(Sender:TObject);
begin
if (MessageDlg('Are you sure you want to delete this definition?',
mtInformation, [mbYes, mbNo], 0) mrYes) then
Exit;
OraSession.StartTransaction;
try
try
tblDefinitions.Delete;
except
on e: EOraError do
begin
OraSession.Rollback;
MessageDlg('#1 - ' + e.Message, mtWarning, [mbOK], 0);
end;
on e: EDatabaseError do
begin
OraSession.Rollback;
MessageDlg('#2 - ' + e.Message, mtWarning, [mbOK], 0);
end;
on e: Exception do
begin
OraSession.Rollback;
MessageDlg('#3 - ' + e.Message, mtWarning, [mbOK], 0);
end;
else
OraSession.Rollback;
MessageDlg('#4 - An error occured.', mtWarning, [mbOK], 0);
end;
finally
if OraSession.InTransaction then
OraSession.Commit;
end;
TIA!