SQL/MP Programming Manual for C
Error and Status Reporting
HP NonStop SQL/MP Programming Manual for C—429847-008
9-8
Using the WHENEVER Directive
Avoiding Infinite Loops
To avoid an infinite loop if the error handling code generates errors or warning, you can
disable the WHENEVER directive within the error handling procedure. An infinite loop
can occur in these situations:
The SQLERROR condition runs a statement that generates an error.
The SQLWARNING condition runs a statement that generates a warning.
The NOT FOUND condition runs a statement that generates a
NOT FOUND condition.
To avoid these situations, disable the appropriate WHENEVER directive for the part of
the program that handles the condition. Example 9-2 on page 9-9 enables and disables
the WHENEVER directive.
Using the CALL Format
To use the CALL format to execute an error handling function, specify the WHENEVER
directive globally and follow it with a forward declaration of the error handling functions.
Also, ensure that each error handling function is accessible from all SQL statements
affected by the WHENEVER directive.
Using the GOTO Format
To use the GOTO (or GO TO) format, specify the WHENEVER directive at the
beginning of the function containing the GOTO format and disable it at the end of the
function. This example enables and disables the WHENEVER directive:
void func(void)
{
EXEC SQL WHENEVER SQLERROR GOTO :error_handler;
/* error_handler function */
...
EXEC SQL WHENEVER SQLERROR; /* disable WHENEVER */
}