Scope rules - user-defined exceptions, PL-SQL Programming

Scope Rules

You cannot declare an exception twice in the similar block. Though, you can, declare the similar exception in 2 different blocks. The Exceptions declared in a block are considered local to that block and global to all its sub-blocks. As a block can reference only local or global exceptions, enclosing the blocks cannot reference the exceptions declared in the sub-block. If you re-declare a global exception in a sub-block, the local declarations prevail. Therefore, the sub-block cannot reference the global exception unless it was declared in the labeled block, in that situation the syntax below is valid:

block_label.exception_name

The illustration below describes the scope rules:

DECLARE

past_due EXCEPTION;

acct_num NUMBER;

BEGIN

DECLARE ---------- sub-block begins

past_due EXCEPTION; -- this declaration prevails

acct_num NUMBER;

BEGIN

...

IF ... THEN

RAISE past_due; -- this is not handled

END IF;

END; ------------- sub-block ends

EXCEPTION

WHEN past_due THEN -- does not handle RAISEd exception

...

END;

The enclosed blocks do not handle the raised exception as the declarations of past_due in the sub-block prevail. Though they share the similar name, the two past_due exceptions are unlike, just as the two acct_num variables share the similar name but are various variables. Hence, the RAISE statement and WHEN clause refer to various exception. To have the enclosing block handle the raised exception, you should remove its declaration from the sub-block or define the OTHERS handler.

Posted Date: 10/5/2012 5:12:42 AM | Location : United States







Related Discussions:- Scope rules - user-defined exceptions, Assignment Help, Ask Question on Scope rules - user-defined exceptions, Get Answer, Expert's Help, Scope rules - user-defined exceptions Discussions

Write discussion on Scope rules - user-defined exceptions
Your posts are moderated
Related Questions
Write an anonymous block that contains a PL/SQL procedure. The procedure takes two input parameter: oldZip and newZip, and it updates the zipcodes table by replacing all oldZip wit

Example of GROUPBY Operator Example: How many students sat each exam, using GROUP BY, NATURAL LEFT JOIN, and COALESCE SELECT CourseId, COALESCE (n, 0) AS n FROM COURS

Project Description: I want to rebuild it and add better content to it It will include up to 5 forms The data will be saved on SQL server and the data access layer could b

%ISOPEN The %ISOPEN yields TRUE if its cursor or cursor variable is open; or else, the %ISOPEN yields FALSE. In the illustration, you use the %ISOPEN to select an action:

Using SET TRANSACTION You use the SET TRANSACTION statement to begin the read-only or read-write transaction, start an isolation level, or assign your present transaction to a

Recursion The Recursion is a powerful method for simplify the design of the algorithms. Principally, the recursion means the self-reference. In the recursive mathematical serie

Semidifference via EXCEPT and JOIN - SQL SELECT * FROM (SELECT StudentId FROM IS_CALLED WHERE Name = 'Devinder' EXCEPT DISTINCT CORRESPONDING SELECT StudentId

Advantages of Packages The benefits of the Packages are as shown below: Modularity The Packages encapsulate logically associated items, types, and subprograms in the

Dynamic SQL: The Most PL/SQL programs do a predictable, specific job. For illustration, a stored procedure may accept an employee number and salary increase, and then update t

Data Types in SQL - Integer INTEGER or  synonymously INT, for integers within a certain range. SQL additionally has types SMALLINT and BIGINT for certain ranges of integers. T