PL/SQL User's Guide and Reference

Contents Index Home Previous Next

EXCEPTION_INIT Pragma

Description

The pragma EXCEPTION_INIT associates an exception name with an Oracle error number. That allows you to refer to any internal exception by name and to write a specific handler for it instead of using the OTHERS handler. For more information, see "Using EXCEPTION_INIT" [*].

Syntax

exception_init_pragma ::=

PRAGMA EXCEPTION_INIT (exception_name, error_number);

Keyword and Parameter Description

PRAGMA

This keyword signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They do not affect the meaning of a program; they simply convey information to the compiler.

exception_name

This identifies a user-defined exception previously declared within the current scope.

error_number

This is any valid Oracle error number. These are the same error numbers returned by the function SQLCODE.

Usage Notes

You can use EXCEPTION_INIT in the declarative part of any PL/SQL block, subprogram, or package. The pragma must appear in the same declarative part as its associated exception, somewhere after the exception declaration.

Be sure to assign only one exception name to an error number.

Example

The following pragma associates the exception insufficient_privileges with Oracle error -1031:

DECLARE
   insufficient_privileges EXCEPTION;
   PRAGMA EXCEPTION_INIT(insufficient_privileges, -1031);
BEGIN
   ...
EXCEPTION
   WHEN insufficient_privileges THEN
      -- handle the error
END;

Related Topics

Exceptions, SQLCODE Function


Contents Index Home Previous Next