Which statement is true about the execution of the code?

View the Exhibit to examine the PL/SQL code.

Which statement is true about the execution of the code?

View the Exhibit to examine the PL/SQL code.

Which statement is true about the execution of the code?

A.
The exception raised in the code is handled by the exception handler for the PAST_DUE exception.

B.
It does not execute because you cannot declare an exception with a similar name in the subblock.

C.
The PAST_DUE exception raised in the subblock causes the program to terminate abruptly because there is no exception handler in the subblock.

D.
The PAST_DUE exception raised by the enclosing block is not propagated to the outer block and it is handled by the WHEN OTHERS exception handler



Leave a Reply 18

Your email address will not be published. Required fields are marked *


howard

howard

answer is C

se_abhi

se_abhi

D is the right answer

vin

vin

yes D is the right ans.

Uladzimir

Uladzimir

Right answer is C.

Here is explanations from oracle documetation:

The enclosing block does not handle the raised exception because the declaration of past_due in the sub-block prevails. Though they share the same name, the two past_due exceptions are different, just as the two acct_num variables share the same name but are different variables. Thus, the RAISE statement and the WHEN clause refer to different exceptions. To have the enclosing block handle the raised exception, you must remove its declaration from the sub-block or define an OTHERS handler.

link to the doc:
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/errors.htm#i1863

Test:
DECLARE
past_due EXCEPTION;
acct_num NUMBER;
BEGIN
DECLARE ———- sub-block begins
past_due EXCEPTION; — this declaration prevails
acct_num NUMBER;
due_date DATE := SYSDATE – 1;
todays_date DATE := SYSDATE;
BEGIN
IF due_date < todays_date THEN
RAISE past_due; — this is not handled
END IF;
END; ————- sub-block ends
EXCEPTION
— Does not handle raised exception
WHEN past_due THEN
DBMS_OUTPUT.PUT_LINE
('Handling PAST_DUE exception.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE
('Could not recognize PAST_DUE_EXCEPTION in this scope.');
raise;
END;
Error at line 1
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at line 23

piero

piero

HY VLADIMIR
be careful
it’s all right but,
if enclosed block don’t find exception named handle, plsql try to find it in enclosign block and in enclosing block there is a when other handle exception….

piero

piero

D

:)

:)

@piero. You are right

DECLARE
past_due EXCEPTION;
acct_num NUMBER;
BEGIN
DECLARE
past_due EXCEPTION;
acct_num NUMBER;
due_date DATE := sysdate -1;
todays_date DATE :=sysdate;
BEGIN
IF due_date < todays_date THEN
RAISE past_due;
END IF;
END;
EXCEPTION
WHEN past_due THEN
dbms_output.put_line ('Handling PAST_DUE exception.');
WHEN OTHERS THEN
dbms_output.put_line ('Could not recognize exception.');
END;
/

Ahmed

Ahmed

D is correct answer
The exception is overrided in inner block