Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

WHENEVER

Use the WHENEVER statement to trap exceptions that occur during the execution of SQL statements. Use this statement only with ESQL/C.

Syntax

Read syntax diagramSkip visual syntax diagram>>-WHENEVER--+-SQLERROR----------+------------------------------>
             +-NOT FOUND---------+
             |  (1)              |
             +--------SQLWARNING-+
             |  (1)              |
             '--------ERROR------'
 
>--+-CONTINUE--------------------+-----------------------------><
   +-+-GOTO--+--+-:label-------+-+
   | '-GO TO-'  |  (1)         | |
   |            '--------label-' |
   +-CALL--routine---------------+
   '-STOP------------------------'
 
Notes:
  1. Informix extension

Element Description Restrictions Syntax
label Statement label to which program control transfers when an exception occurs Must exist in the same source-code module. Language-specific
routine Name of a user-defined routine (UDR) to be invoked when an exception occurs No arguments; UDR must exist at compile time. Database Object Name

Usage

The WHENEVER statement is equivalent to placing an exception-checking routine after every SQL statement. The following table summarizes the types of exceptions for which you can check with the WHENEVER statement.

Type of Exception WHENEVER Keyword For More Information
Errors SQLERROR or ERROR SQLERROR Keyword
Warnings SQLWARNING Keyword
Not Found or End of Data NOT FOUND Keywords

Programs that do not use the WHENEVER statement do not automatically abort when an exception occurs. Such programs must explicitly check for exceptions and take whatever corrective action their logic specifies. If you do not check for exceptions, the program simply continues running. If errors occur, however, the program might not perform its intended purpose.

The first keyword that follows WHENEVER specifies some type of exceptional condition; the last part of the statement specifies some action to take when the exception is encountered (or no action, if CONTINUE is specified). The following table summarizes possible actions that WHENEVER can specify.

Type of Action WHENEVER Keyword For More Information
Continue program execution CONTINUE Keyword
Stop program execution STOP Keyword
Transfer control to a specified label GOTO
GO TO
GOTO Keyword
Transfer control to a UDR CALL Clause
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]