>>-RAISE EXCEPTION--SQL_error_var-------------------------------> >--+----------------------------------+--;--------------------->< '-,--ISAM_error--+---------------+-' '-,--error_text-'
Element | Description | Restrictions | Syntax |
---|---|---|---|
error_text | SPL variable or expression that contains the error message text | Must be a character data type and be valid in the statement block | Identifier;
Expression |
ISAM_error | SPL variable or expression that represents an ISAM error number. The default is 0. | Must return a value in SMALLINT range. You can specify a unary minus sign before error number. | Identifier;
Expression |
SQL_error | SPL variable or expression that represents an SQL error number | Same as for ISAM_error | Identifier;
Expression |
Use the RAISE EXCEPTION statement to simulate an error or to generate an error with a custom message. An ON EXCEPTION statement can trap the generated error.
If you omit ISAM_error, the database server sets the ISAM error code to zero (0) when the exception is raised. If you want to specify error_text but not specify a value for ISAM_error, specify zero (0) as the value of ISAM_error.
The RAISE EXCEPTION statement can raise either system-generated exceptions or user-generated exceptions. For example, the following statement raises the error number -208 and inserts the text a missing file into the variable of the system-generated error message:
RAISE EXCEPTION -208, 0, 'a missing file';
Here the minus ( - ) symbol is required after the EXCEPTION keyword for error -208; most error codes are negative integers.
The special error number -746 allows you to produce a customized message. For example, the following statement raises the error number -746 and returns the quoted text:
RAISE EXCEPTION -746, 0, 'You broke the rules';
In the following example, a negative value for alpha raises exception -746 and provides a specific message that describes the problem. The code should contain an ON EXCEPTION statement that traps for an exception of -746.
FOREACH SELECT c1 INTO alpha FROM sometable IF alpha < 0 THEN RAISE EXCEPTION -746, 0, 'a < 0 found' -- emergency exit END IF END FOREACH
When the SPL routine executes and the IF condition is met, the database server returns the following error:
-746: a < 0 found.
For more information about the scope and compatibility of exceptions, see ON EXCEPTION.