13.27 Exception Handler
An exception handler processes a raised exception.
Exception handlers appear in the exception-handling parts of anonymous blocks, subprograms, triggers, and packages.
Topics
Syntax
Semantics
exception_handler
exception
Name of either a predefined exception (see Table 11-3) or a user-defined exception (see "Exception Declaration").
If PL/SQL raises a specified exception, then the associated statements run.
OTHERS
Specifies all exceptions not explicitly specified in the exception-handling part of the block. If PL/SQL raises such an exception, then the associated statements run.
Note:
Oracle recommends that the last statement in the OTHERS
exception handler be either RAISE
or an invocation of the RAISE_APPLICATION_ERROR
procedure.
If you do not follow this practice, and PL/SQL warnings are enabled, you get PLW-06009.
In the exception-handling part of a block, the WHEN
OTHERS
exception handler is optional. It can appear only once, as the last exception handler in the exception-handling part of the block.
Examples
-
Example 11-3, "Single Exception Handler for Multiple Exceptions"
-
Example 11-4, "Locator Variables for Statements that Share Exception Handler"
-
Example 11-6, "Anonymous Block Handles ZERO_DIVIDE"
-
Example 11-7, "Anonymous Block Avoids ZERO_DIVIDE"
-
Example 11-10, "Declaring, Raising, and Handling User-Defined Exception"
-
Example 11-14, "Exception that Propagates Beyond Scope is Handled"
-
Example 11-24, "Exception Handler Runs and Execution Ends"
-
Example 11-25, "Exception Handler Runs and Execution Continues"
-
Example 12-12, "Handling FORALL Exceptions Immediately"
-
Example 12-13, "Handling FORALL Exceptions After FORALL Statement Completes"