EXCEPTION Clause

Exception Clause

1  EXCEPTION
1 exception_num
1 exception_var
2 + , information  = 
3.1 CLASS_ORIGIN
3.1 CONNECTION_NAME
3.1 INFORMIX_SQLCODE
3.1 MESSAGE_LENGTH
3.1 MESSAGE_TEXT
3.1 RETURNED_SQLSTATE
3.1 SERVER_NAME
3.1 SUBCLASS_ORIGIN
Element Description Restrictions Syntax
exception_num Number of exceptions Integer in range 1 to 35,000 Literal Number
exception_var Variable storing exception_num Must be SMALLINT or INT Language specific
information Host variable to receive the value of a specified exception field Data type must match that of the specified field Language specific

The exception_num literal indicates one of the exception values from the number of exceptions that the NUMBER field in the Statement clause returns.

When retrieving exception information, GET DIAGNOSTICS writes the values of each of the seven fields into corresponding host variables. These fields are located in the diagnostics area and are derived from an exception raised by the most recent SQL statement.

The host-variable data type must be the same as that of the requested field. The following table describes the seven exception information fields.
Field Name Keyword Field Data Type Field Contents ESQL/C Host Variable Data Type
RETURNED_SQLSTATE Character SQLSTATE value char[6]
INFORMIX_SQLCODE Integer HCL OneDB™-specific status code int4
CLASS_ORIGIN Character String char[255]
SUBCLASS_ORIGIN Character String char[255]
MESSAGE_TEXT Character String char[255]
MESSAGE_LENGTH Integer Numeric value int
SERVER_NAME Character String char[255]
CONNECTION_NAME Character String char[255]

The application specifies the exception by number, using either an unsigned integer or an integer host variable (an exact numeric with a scale of 0). An exception with a value of 1 corresponds to the SQLSTATE value set by the most recent SQL statement other than GET DIAGNOSTICS. The association between other exception numbers and other exceptions raised by that SQL statement is undefined. Thus, no set order exists in which the diagnostic area can be filled with exception values. You always get at least one exception, even if the SQLSTATE value indicates success.

If an error occurs within the GET DIAGNOSTICS statement (that is, if an invalid exception number is requested), the HCL OneDB internal SQLCODE and SQLSTATE variables are set to the value of that exception. In addition, the GET DIAGNOSTICS fields are undefined.