>>-WHENEVER--+-SQLERROR----------+------------------------------> +-NOT FOUND---------+ | (1) | +--------SQLWARNING-+ | (1) | '--------ERROR------' >--+-CONTINUE--------------------+----------------------------->< +-+-GOTO--+--+-:label-------+-+ | '-GO TO-' | (1) | | | '--------label-' | +-CALL--routine---------------+ '-STOP------------------------'
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 |
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 |