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
FireBird Exception Data
-
AndreyZ
Re: FireBird Exception Data
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:Note that to run this code, you should add the IBCError unit to the USES clause of your unit.
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;Re: FireBird Exception Data
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.
There are other exceptions and I need to display different messages suitable for each one.
-
AndreyZ
Re: FireBird Exception Data
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
Many thanks. I think I will move the logic to Delphi before post event as it give better control.