SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
13-1
13
Exception Handling and Error
Conditions
In NonStop SQL/MX, a warning or error condition is also referred to as an exception.
Your host language application program can detect these exceptions and can gather
diagnostic information after the execution of each of the program’s SQL statements. To
properly account for various error scenarios, you need to be aware of the variety of
exceptions that exist and some of the options that you can use to handle them:
•
You can check the value of an SQLSTATE variable and then use the GET
DIAGNOSTIC statement to obtain SQL/MX-specific exception information after
each SQL statement.
•
You can use the WHENEVER statement to map a particular action or response to
an error or warning each time that error or warning occurs.
This section provides information for detecting and handling various types of
exceptions.
This section describes:
•
Checking the SQLSTATE Variable on page 13-1
•
Checking the SQLCODE Variable on page 13-5
•
SQL/MX Exception Condition Messages on page 13-7
•
Using the WHENEVER Statement on page 13-8
•
Accessing and Using the Diagnostics Area on page 13-13
•
Special SQL/MX Error Conditions on page 13-15
Checking the SQLSTATE Variable
After the execution of each SQL statement, NonStop SQL/MX returns a value to the
SQLSTATE variable to indicate the results of the statement. A host language program
can use conditional statements to check the SQLSTATE value to determine the results
of execution.
While NonStop SQL/MX does support the SQLCODE variable, use the SQLSTATE
variable to detect exception conditions. For equivalent values, see the SQLSTATE
values returned by NonStop SQL/MX in the SQL/MX Messages Manual.
Declaring SQLSTATE
Declare SQLSTATE within a Declare Section. Use conditional statements to check the
SQLSTATE variable after the execution of an SQL statement.
Note. To write your application to recover from temporary network or hardware service
interruptions, see the SQL/MX Installation and Management Guide.