Subject Error with SQLERROR and SQLCODE in SP
Author Alan J Davies
Hi
I am using FB with various stored procs and have a problem with checking
against errors returned by SQL actions.
How do I use the WHENEVER SQLERROR ....... in a stored proc?
Typically, I want to use my own exception text to inform the user what's
going on, instead of the difficult to understand version generated by
IB/FB. I use exceptions for this purpose in other sps.

e.g. 'Part # Already On File'
instead of
'Attempt to store duplicate value (visible to active
transactions) in unique index "PARTNO" '

I can code around this by setting exceptions within Delphi ( which I have
already had to do ) but that means a more complicated app. - and it may
also be needed in different apps - and anyway - it should work at the
database level, otherwise why have the commands?

I have tried various methods using SQLERROR and SQLCODE but get error
messages such as

Dynamic SQL Error
SQL error code = -104
Token unknown - line 7, char 12
SQLERROR
Statement: CREATE PROCEDURE PARTNO_INSERT

when trying to compile the following sp

CREATE PROCEDURE PARTNO_INSERT
(
PART_NMBR CHAR(16) /* New Part # */
)
AS
Begin /* Partno is Unique
- Index exists and works ok */
Whenever SQLERROR Do /* If any error */
Exception InsertPart; /* Display my own message */
Insert into Partnos(Partno) /* Create New Part */
Values (:Part_Nmbr); /* New Part # */
end


Regards
Alan Davies