User-Named Exception Handlers

The technique that is used to bind a numbered exception handler to a name using 'Pragma Exception_init()'.This binding of a numbered exception handler,to a name string, is done in the declare section of the PL/SQL block.

All objects declared in the declare section of a PL/SQL block are not created until actually required within the PL/SQL block. However, the binding of a numbered exception handler to a name must be done exactly when declared not when the exception handler is invoked due to an exception condition.

The Pragma action word is a call to a pre-compile, which immediately binds the numbered exception handler to a name when encountered.

The function Exception_init() takes two parameters the first is the user defined exception name the second is the Oracle engine's exception number. These lines will be included in the Declare section of the PL/SQL block.

Note: The user defined exception name must be the statement that immediately preceds the Pragma Exception_init() statement.

Syntax:

Declare exception_name EXCEPTION;
PRAGMA EXCEPTION_INIT(exception_name,error_code_no);
BEGIN

Using this technique it is possible to bind appropriate numbered exception handlers to names and use these names in the exception section of a PL/SQL block. When this is done the default exception handling code of the exception handler is overridden and the user-defined exception handling code is executed.

Syntax:

DECLARE
exception_name EXCEPTION;
PRAGMA EXCEPTION_INIT(exception_name,error_code_no);
BEGIN
--------
--------
EXCEPTION
WHEN exception_name THEN

END;
Share/Bookmark

No comments: