Page 1 of 1

FireBird Exception Data

Posted: Tue 22 Jan 2013 22:14
by inageib
Hi,
I have a stored procedure in my FireBird DB v2.5 that throw an exception. example message:

---------------------------
My App
---------------------------
exception 5
My_Exception_Name
You made a mistake At procedure 'My_proc' line: 14, col: 114
At trigger 'trigger_name_BIU10' line: 6, col: 3.
---------------------------
OK
---------------------------
This is the exact message but obviously I dont want to display exception name, stored procedure name !, trigger name and line info !!

Is there a way to hid these info and display the message 'You made a mistake' only ?

Thanks

Re: FireBird Exception Data

Posted: Wed 23 Jan 2013 12:12
by AndreyZ
Hello,

IBDAC shows exception messages exactly as Firebird sends them. If you want to provide your own messages, you should catch the exception and modify its Message property. Here is a code example:

Code: Select all

begin
  try
    IBCStoredProc.StoredProcName := 'THROWEXCEPTION'; // the THROWEXCEPTION stored proc generates some exception
    IBCStoredProc.Execute;
  except
    on E: EIBCError do begin
      E.Message := 'You made a mistake'; // your custom exception message
      raise;
    end;
  end;
end;
Note that to run this code, you should add the IBCError unit to the USES clause of your unit.

Re: FireBird Exception Data

Posted: Fri 25 Jan 2013 00:18
by inageib
I can not use the exact way. I use table and when I call the .post method the trigger call for a stored proc which raise the exception. is there a way to catch exception My_Exception_Name only ? like error code ?

There are other exceptions and I need to display different messages suitable for each one.

Re: FireBird Exception Data

Posted: Fri 25 Jan 2013 09:50
by AndreyZ
Unfortunately, Firebird returns the name of an occured exception only in the message of the exception. Therefore, you can use the following code:

Code: Select all

begin
  try
    IBCStoredProc.StoredProcName := 'THROWEXCEPTION'; // the THROWEXCEPTION stored proc generates some exception
    IBCStoredProc.Execute;
  except
    on E: EIBCError do begin
      if Pos('My_Exception_Name', E.Message) > 0 then
        E.Message := 'You made a mistake'; // your custom exception message
      raise;
    end;
  end;
end;

Re: FireBird Exception Data

Posted: Fri 25 Jan 2013 14:01
by inageib
Many thanks. I think I will move the logic to Delphi before post event as it give better control.

Re: FireBird Exception Data

Posted: Fri 25 Jan 2013 14:30
by AndreyZ
I am glad I could help.