>>-ON EXCEPTION--+----------------------------+-----------------> | .-,------------. | | V | | '-IN--(----error_number-+--)-' >--+-------------------------------------------+----------------> '-SET--SQL_error_var--+-------------------+-' +-,--ISAM_error_var-+ '-,--error_data_var-' (1) >--| Statement Block |-------END EXCEPTION--+-------------+-----> '-WITH RESUME-' >--+---+------------------------------------------------------->< '-;-'
Element | Description | Restrictions | Syntax |
---|---|---|---|
error_data_var | SPL variable to receive a string returned by an SQL error or by a user-defined exception | Must be a character type to receive the error information. Must be valid in current statement block. | Identifier |
error_number | SQL error number or a number defined by a RAISE EXCEPTION statement that is to be trapped | Must be of integer type. Must be valid in current statement block. | Literal Number |
ISAM_error_var | SPL variable that receives the ISAM error number of the exception raised | Same as for error_number | Identifier |
SQL_error_var | SPL variable that receives the SQL error number of the exception raised | Same as for ISAM_error_var | Identifier |
The ON EXCEPTION statement, together with the RAISE EXCEPTION statement, provides an error-trapping and error-recovery mechanism for SPL. ON EXCEPTION can specify the errors that you want to trap as the SPL routine executes, and specifies the action to take if the error occurs within the statement block. ON EXCEPTION can specify an error number list in the IN clause, or can include no IN clause. If the IN clause is omitted, then all errors are trapped.
A statement block can include more than one ON EXCEPTION statement. The exceptions that are trapped can be either system-defined or user-defined.
The scope of an ON EXCEPTION statement is the statement block that follows the ON EXCEPTION statement, and all the statement blocks that are nested within that statement block.
When an exception is trapped, the error status is cleared.
If you specify a variable to receive an ISAM error, but no accompanying ISAM error exists, a zero (0) is assigned to the variable. If you specify a variable to receive the error text, but none exists, the variable stores an empty string.
ON EXCEPTION has no effect within a UDR that is called by a trigger.
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]