SQL Programming Manual for Pascal

Error and Status Processing
HP NonStop SQL Programming Manual for Pascal528614-001
6-5
Using the WHENEVER Directive
EXEC SQL
WHENEVER SQLERROR ; { Disables checking }
Using the CALL Format
If you use the CALL format of WHENEVER, follow these guidelines:
Specify the WHENEVER directive globally and precede the directive with a
FORWARD declaration of the error handling procedure(s).
Declare the procedure or subprocedure without parameters, and do not allow it to
return a value.
Ensure that the procedure or subprocedure you call is accessible from each SQL
statement affected by the WHENEVER directive.
Using the GOTO Format
If you use the GOTO (or GO TO) format, specify the WHENEVER directive at the
beginning of the procedure containing the GOTO and disable it at the end of the
procedure. For example:
PROCEDURE WORK;
LABEL ERROR_HANDLER;
BEGIN
EXEC SQL WHENEVER SQLERROR GOTO :ERROR_HANDLER;
...
ERROR_HANDLER:
(error handling code)
...
EXEC SQL WHENEVER SQLERROR; { Disable WHENEVER directive }
END ;
Determining the Scope of a WHENEVER Directive
The order in which WHENEVER directives appear in a program determines their scope
or range of effect. Some points to consider are:
A WHENEVER directive is in effect until another WHENEVER directive for the
same condition appears.
If another procedure is called within the error handling code, the position of the
called procedure in the program order determines the WHENEVER clause that is
in effect. The context of the calling procedure has no effect.
The program order includes files that are copied into the program using a Pascal
SOURCE directive. If a copied file contains a WHENEVER directive, that directive
is in effect following the SOURCE directive.
SQL statements are not affected by the WHENEVER directive if they appear in the
program before the WHENEVER directive enables condition checking.