Database Reference
In-Depth Information
Error handling
ECPG provides multiple mechanisms to handle exceptional conditions and
warnings. The following are the mechanisms used for error handling:
• Setting callback using the WHENEVER statement
• Using the sqlca variable to check for detailed information about the error
and warning
How to set an error callback
The WHENEVER command is used to set the condition and action. The actions
are called when the condition is met. The syntax for the WHENEVER statement
is as follows:
EXEC SQL WHENEVER condition action;
Conditions
There are three conditions we can specify in the WHENEVER conditions: SQLERROR ,
SQLWARNING , and NOT FOUND . Let's understand them one by one:
SQLERROR : This condition arises if an error occurs while executing the SQL
statement. Its syntax is as follows:
EXEC SQL WHENEVER SQLERROR GOTO error_label;
SQLWARNING : This condition arises if a warning occurs while executing the
SQL statement. Its syntax is as follows:
EXEC SQL WHENEVER SQLWARNING GOTO warning_label;
NOT FOUND : This condition arises if there is no or zero row found. Its syntax is
as follows:
EXEC SQL WHENEVER NOT FOUND GOTO no_more_rows_label;
NOT FOUND is not an error condition, but this is an important
information for the program.
The error_label , warning_label , and no_more_label are
C language labels.
 
Search WWH ::




Custom Search