Subject | Re: [firebird-support] Exception Messages |
---|---|
Author | Helen Borrie |
Post date | 2005-03-17T00:13:54Z |
At 05:21 PM 16/03/2005 -0600, you wrote:
Look at the use of custom exceptions in your trigger validation code.
Create an exception that you can raise when the validation fails. If you are using v. 1.5.x, the text that you enter in the CREATE EXCEPTION spec doesn't matter, as you can customise at run-time the string that gets returned as the exception text, up to a limit of 78 bytes.
Briefly,
CREATE EXCEPTION BAD_STOCK_UPDATE ''Any old thing';
commit;
create trigger blah for stockquantity
active before insert or update position 1
as
declare bad_stock_msg varchar(78);
begin
if (new.icount < 0) then
begin
bad_stock_msg = 'Part # -' || new.PARTNUM || 'Attempted Change = '|| cast(new.icount as varchar(10) || '. You may not set an inventory count lower than zero.';
exception BAD_STOCK_UPDATE bad_stock_msg;
end
end
Just be conservative enough with the message text that it doesn't risk overflowing the 78-byte limit. (In Fb 2 you'll have about 1000 bytes to play with.)
./hb
>Hello,There's always another way. :-)
>
>I am currently having a problem where I wish to return more specific
>information about my Exceptions when they happen.
>
>Currently I prevent users from setting an inventory count below < 0 on
>inventory.
>
>However when they do try to do this I send them an exception with a message
>of "You may not set an inventory count <0".
>
>I would like to expand that definition from the trigger to include
>information specific from the point where the originated - something like
>
>"Part # -xxxxxxxx Attempted Change = xxx. You may not set an inventory count
>."
>
>All I can see is that you can only send static predefined messages.
>
>Is there another way ?
Look at the use of custom exceptions in your trigger validation code.
Create an exception that you can raise when the validation fails. If you are using v. 1.5.x, the text that you enter in the CREATE EXCEPTION spec doesn't matter, as you can customise at run-time the string that gets returned as the exception text, up to a limit of 78 bytes.
Briefly,
CREATE EXCEPTION BAD_STOCK_UPDATE ''Any old thing';
commit;
create trigger blah for stockquantity
active before insert or update position 1
as
declare bad_stock_msg varchar(78);
begin
if (new.icount < 0) then
begin
bad_stock_msg = 'Part # -' || new.PARTNUM || 'Attempted Change = '|| cast(new.icount as varchar(10) || '. You may not set an inventory count lower than zero.';
exception BAD_STOCK_UPDATE bad_stock_msg;
end
end
Just be conservative enough with the message text that it doesn't risk overflowing the 78-byte limit. (In Fb 2 you'll have about 1000 bytes to play with.)
./hb