RAISE

Raises an exception.

For more information about exceptions, see Handling Exceptions.

See also

EXCEPTION

Syntax

RAISE <exception_name> ;

Where:

exception_name

The name of the exception to raise.

If you are handling an exception in an exception handler and you want to raise the same exception again, omit this argument. See Raising the Same Exception Again in an Exception Handler.

Examples

This creates and raises (but does not catch) a simple exception:

CREATE PROCEDURE thrower()
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
    DECLARE
        MY_EXCEPTION EXCEPTION;
    BEGIN
        RAISE MY_EXCEPTION;
    END;
$$
;

Here is the call to the stored procedure that raises the exception:

CALL thrower();

Here is the output of executing the stored procedure that raises the exception:

-20000 (P0001): Uncaught exception of type 'MY_EXCEPTION' on line 5 at position 8

The next example is similar to the preceding example, but uses an exception for which the user defined a custom exception number and exception message:

    DECLARE
        MY_EXCEPTION EXCEPTION (-20002, 'Raised MY_EXCEPTION.');

Here is the output of executing the stored procedure that raises the exception:

-20002 (P0001): Uncaught exception of type 'MY_EXCEPTION' on line 7 at position 8 : Raised MY_EXCEPTION.

For more examples, see the examples for handling an exception.

Back to top