WHEN … DO

From InterBase
Jump to: navigation, search

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

EXCEPTION <exception_name>

The name of an exception already in the database

SQLCODE <number>

A SQLCODE error code number

GDSCODE <errcode>

An InterBase error code. Use Table 5.5 and strip isc_ before mentioning the error code with GDSCODE usage. For example: GDSCODE lock_conflict.

ANY

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 a BEGINEND block. It should come after SUSPEND, 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.

Topics