informix
Informix Guide to SQL: Syntax
SPL Statements

RAISE EXCEPTION

Use the RAISE EXCEPTION statement to simulate the generation of an error.

Syntax

Element Purpose Restrictions Syntax
error_text_var SPL variable that contains the error text The SPL variable must be a character data type and must be valid in the statement block. Identifier, p. 4-205
ISAM_error_var Variable or expression that represents an ISAM error number The default value is 0. The variable or expression must evaluate to a SMALLINT value. You can place a minus sign before the error number. Expression, p. 4-73
SQL_error_var Variable or expression that represents an SQL error number The variable or expression must evaluate to a SMALLINT value. You can place a minus sign before the error number. Expression, p. 4-73

Usage

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 the ISAM_error_var parameter, the database server sets the ISAM error code to zero (0) when the exception is raised. If you want to use the error_text_var parameter but not specify a value for ISAM_error_var, you can specify zero (0) as the value of ISAM_error_var.

The 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:

Special Error Numbers

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:

In the following example, a negative value for alpha raises exception -746 and provides a specific message describing the problem. The code should contain an ON EXCEPTION statement that traps for an exception of -746.

When the SPL routine executes and the IF condition is met, the database server returns the following error:

For more information about the scope and compatibility of exceptions, see ON EXCEPTION.


Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved