Professional Documents
Culture Documents
When an exception occurs, PL/SQL looks for an exception handler in the current
block e.g., anonymous
block, procedure, or function of the exception. If it does not find a match, PL/SQL
propagates the
exception to the enclosing block of the current block.
PL/SQL then attempts to handle the exception by raising it once more in the
enclosing block. This
process continues in each successive enclosing block until there is no remaining
block in which to raise
the exception. If there is no exception handler in all blocks, PL/SQL returns an
unhandled exception to
the application environment that executed the outermost PL/SQL block.
DECLARE
e1 EXCEPTION;
PRAGMA exception_init (e1, -20001);
e2 EXCEPTION;
PRAGMA exception_init (e2, -20002);
e3 EXCEPTION;
PRAGMA exception_init (e2, -20003);
l_input NUMBER := &input_number;
BEGIN
Because the input is 1, the inner block raises the e1 exception. The exception-
handling part of the inner
block handles the e1 exception locally, therefore, the execution of the block
resumes in the enclosing
block.
END;
/
The inner block raises the e2 exception. Because the inner block does not have an
exception handler to
handle the e2 exception, PL/SQL propagates the e2 exception to the enclosing block.
The enclosing block has an exception handler that handles e2 exception. Therefore
control passes to
the host environment (SQL*Plus or SQL Developer).
The following picture illustrates the propagation of the unhandled exception from
the inner block to its
enclosing block:
In this case, both inner block and enclosing block has no exception handler to
handle the e3 exception.
Therefore, the block returns an unhandled exception to the host environment.
The following picture illustrates the propagation of the unhandled exception from
the inner block to its
enclosing block, and then host environment:
In this tutorial, you have learned how to PL/SQL propagates the exceptions from the
current block to
the enclosing blocks.