Oracle® Database Administrator's Guide 11g Release 2 (11.2) Part Number E10595-04 |
|
|
View PDF |
When the database executes a procedure locally or at a remote location, four types of exceptions can occur:
PL/SQL user-defined exceptions, which must be declared using the keyword EXCEPTION
PL/SQL predefined exceptions such as the NO_DATA_FOUND
keyword
SQL errors such as ORA-00900
and ORA-02015
Application exceptions generated using the RAISE_APPLICATION_ERROR
() procedure
When using local procedures, you can trap these messages by writing an exception handler such as the following
BEGIN ... EXCEPTION WHEN ZERO_DIVIDE THEN /* ... handle the exception */ END;
Notice that the WHEN
clause requires an exception name. If the exception does not have a name, for example, exceptions generated with RAISE_APPLICATION_ERROR
, you can assign one using PRAGMA_EXCEPTION_INIT
. For example:
DECLARE null_salary EXCEPTION; PRAGMA EXCEPTION_INIT(null_salary, -20101); BEGIN ... RAISE_APPLICATION_ERROR(-20101, 'salary is missing'); ... EXCEPTION WHEN null_salary THEN ... END;
When calling a remote procedure, exceptions can be handled by an exception handler in the local procedure. The remote procedure must return an error number to the local, calling procedure, which then handles the exception as shown in the previous example. Note that PL/SQL user-defined exceptions always return ORA-06510
to the local procedure.
Therefore, it is not possible to distinguish between two different user-defined exceptions based on the error number. All other remote exceptions can be handled in the same manner as local exceptions.
See Also:
Oracle Database PL/SQL Language Reference for more information about PL/SQL procedures