Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ankur.

Asked: November 03, 2017 - 2:39 pm UTC

Last updated: November 04, 2017 - 1:16 am UTC

Version: 9

Viewed 1000+ times

You Asked

create or replace procedure proc_delme
is
n number:=1/0;
begin

dbms_output.put_line(n);
exception
when others then
dbms_output.put_line(sqlerrm);
end proc_delme;
/

If I do following then raised error is not handled
begin
proc_delme;
end;
/

If I do following then raised error is handled
begin
proc_delme;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
/

My question is that is there any other way to handle exception raised in declaration section other than which I showed.

and Connor said...

Not really. The error is handled by an exception handler in the *current* block, where "block" is defined by "begin-end".

So when you have

declare
   [something that goes wrong]
begin
   ...
end


so because we haven't "entered" the begin, we propagate the exception up to the next level.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, November 05, 2017 - 10:42 am UTC


Given issue

ajit kulshrestha, November 17, 2017 - 9:10 am UTC

Always make a practice to initialize variable in Begin-end block for handling the exception .

ex :

create or replace procedure proc_delme
is
n number;
begin
n:=1/0;
dbms_output.put_line(n);
exception
when others then
dbms_output.put_line(sqlerrm);
end proc_delme;

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library