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
heap sort program in pl/sql

Negation (NOT, ¬) - SQL There are three rows instead of just two. As you can see, ¬ p is defined as in two-valued logic (2VL) when p is either true or false, but ¬ (unknown) i

Expressions   An expression is a randomly complex combination of the constants, variables, literals, operators, & function calls. The simplest expression is the single variabl

Use the NOCOPY Compiler Hint By default, the OUT and IN OUT parameters are passed by the value i.e. the value of an IN OUT actual parameter is copied into the corresponding fo

Explicit Cursors The set of rows returned by the query can include zero, one, or multiple rows, depending on how many rows meet your search criteria. Whenever a query returns

V ariables and Constants in PL/SQL The PL/SQL permits you to declare constants and variables, and then use them in SQL and procedural statements anywhere in the expression. Th

I want to implement heap sort algorithm in pl sql please share the source code for guidance

Parameter and Keyword Description: cursor_name: This identifies an explicit cursor formerly declared within the present scope. cursor_variable_name: These identif

Data Types in SQL - Timestamp TIMESTAMP for values representing points in time on a specified uniform scale. DATE is used for timestamps on a scale of one day, such as DATE '2

Records Records are the items of the type RECORD. The Records have exclusively named fields that can store the data values of various types. And hence, a record treat associate