FireBird Exception Data

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

FireBird Exception Data

Post by inageib » Tue 22 Jan 2013 22:14

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

AndreyZ

Re: FireBird Exception Data

Post by AndreyZ » Wed 23 Jan 2013 12:12

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.

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: FireBird Exception Data

Post by inageib » Fri 25 Jan 2013 00:18

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.

AndreyZ

Re: FireBird Exception Data

Post by AndreyZ » Fri 25 Jan 2013 09:50

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;

inageib
Posts: 184
Joined: Wed 26 Aug 2009 14:11

Re: FireBird Exception Data

Post by inageib » Fri 25 Jan 2013 14:01

Many thanks. I think I will move the logic to Delphi before post event as it give better control.

AndreyZ

Re: FireBird Exception Data

Post by AndreyZ » Fri 25 Jan 2013 14:30

I am glad I could help.

Post Reply