Handling Errors
Go Up to Working with Stored Procedures
Procedures can handle three kinds of errors with a WHEN … DO statement:
- Exceptions raised by
EXCEPTIONstatements 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 errors reported in
GDSCODE.
The WHEN ANY statement handles any of the three types of errors.
For more information about InterBase error codes and SQLCODE values, see the Language Reference.
The syntax of the WHEN … DO statement is:
WHEN {<error> [, <error> …] | ANY}
DO <compound_statement>
<error> =
{EXCEPTION exception_name | SQLCODE number | GDSCODE errcode}
- Important: If used,
WHENmust be the last statement in aBEGIN … ENDblock. It should come afterSUSPEND, if present.