WHEN … DO
Go Up to Procedures and Triggers
Error-handling statement that performs the statements following DO
when the specified error occurs. Available in triggers and stored procedures.
WHEN {<error> [, <error> …] | ANY}
DO <<compound_statement>>
<error>=
{EXCEPTION exception_name | SQLCODE number | GDSCODE errcode}
Argument | Description |
---|---|
|
The name of an exception already in the database |
|
A |
|
An InterBase error code. Use Table 5.5 and strip isc_ before mentioning the error code with GDSCODE usage. For example: GDSCODE lock_conflict. |
|
Keyword that handles any of the above types of errors. |
<compound_statement> |
Statement or block executed when any of the specified errors occur. |
- Important: If used,
WHEN
must be the last statement in aBEGIN…END
block. It should come afterSUSPEND
, if present.
Description: Procedures can handle three kinds of errors with a WHEN
statement:
- Exceptions raised by
EXCEPTION
statements in the current procedure, in a nested procedure, or in a trigger fired as a result of actions by such a procedure. - SQL errors reported in
SQLCODE
. - InterBase error codes.
The WHEN ANY
statement handles any of the three types.