Subject Re: [firebird-support] Exception with a parameter
Author Helen Borrie
At 12:04 PM 10/12/2004 +0100, you wrote:

>Hi,
>
>is there a way to add a parameter to an exception which
>is displayed in the exception text?
>
>Something like this:
>
>CREATE EXCEPTION E_PA_CM_VERTRAG_NICHT_GEFUNDEN
>'Contract <Param> was not found.'
>
>IF (L_Id IS NULL) THEN
> EXCEPTION E_Pa_Cm_Vertrag_Nicht_Gefunden('434');
>
>This should result in the message
>'Contract 434 not found.' when the exception is fired.
>
>I am using FB 1.50 and I thought I had heard about parameterized
>exceptions, but I cannot find anything in the release notes.

No, not parameterised exceptions. But you can now use an existing
exception and replace its text message when you throw the exception.

For example:

create exception boom ('');

create trigger .............
as
declare errormsg varchar(78);
begin

if (new.pk <> old.pk) then
begin
errormsg = 'Value ' || cast old.pk as varchar(8) || ' cannot be changed';
exception boom errormsg;
end
....

In your case,
...
exception boom 'Contract ' || cast (:param as varchar(8)) || ' was not
found';

./h