Subject Re: [firebird-support] Catching exceptions in trigger
Author Martijn Tonies
Hi Gary,


> I have a trigger that inserts a value into a log table for replication
> purposes.
>
> CREATE TRIGGER BUTTONS_INSERT FOR BUTTONS ACTIVE AFTER INSERT POSITION 0
AS
> BEGIN
> INSERT INTO CHANGE_LOG( SEQUENCE, TABLENAME, LINK, OPERATION)
> VALUES ( gen_id( change_log, 1), 'BUTTONS', NEW.LINK, 'I');
> END
>
> The table it inserts into has a unique index on the LINK, TABLENAME field,
> so if the record exists I get an unwanted exception error in my
application.
> I dont want the additional overhead in the trigger code of checking if
the
> record exists before inserting, so my question is:
> Can I catch this exception 'c-style' inside the trigger and handle it so
my
> appication doesnt know about it

You can use a WHEN block...

WHEN ALL /* catch all exceptions */
DO ;

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com