Oracle® Database PL/SQL User's Guide and Reference 10g Release 2 (10.2) Part Number B14261-01 |
|
|
PDF · Mobi · ePub |
The RAISE
statement stops normal execution of a PL/SQL block or subprogram and transfers control to an exception handler.
RAISE
statements can raise predefined exceptions, such as ZERO_DIVIDE
or NO_DATA_FOUND
, or user-defined exceptions whose names you decide. For more information, see "Defining Your Own PL/SQL Exceptions".
raise statement ::=
Keyword and Parameter Description
exception_name
A predefined or user-defined exception. For a list of the predefined exceptions, see "Summary of Predefined PL/SQL Exceptions".
PL/SQL blocks and subprograms should RAISE
an exception only when an error makes it impractical to continue processing. You can code a RAISE
statement for a given exception anywhere within the scope of that exception.
When an exception is raised, if PL/SQL cannot find a handler for it in the current block, the exception propagates to successive enclosing blocks, until a handler is found or there are no more blocks to search. If no handler is found, PL/SQL returns an unhandled exception
error to the host environment.
In an exception handler, you can omit the exception name in a RAISE
statement, which raises the current exception again. This technique allows you to take some initial corrective action (perhaps just logging the problem), then pass control to another handler that does more extensive correction. When an exception is reraised, the first block searched is the enclosing block, not the current block.
For examples, see the following: