Posted by 'Amit Chauhan' on August 23, 2001 at 20:45:21 EST:
In Reply to: exception posted by 'selvam' on August 23, 2001 at 11:00:55 EST:
Hi,
Exception flows from inside out. If it cant be handled in the inner most block, then it propagates to the one that encloses it. If there is not enclosing block, then it goes back to the calling program. Like this :
DECLAR
temp NUMBER := 0;
BEGIN
BEGIN
select 1 into temp from dual where 1 = 2; -- This statement will raise no_data_found exception
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('In inner block exception');
END;
dbms_output.put_line ('After inner block');
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('In outer block exception');
END;
When you run this pl/sql block, the output will be like this :
In inner block exception
After inner block
pl/sql procedure successfully completed.
If there is no exception handler in the inner block, then it will propage to the outer block, and this will be printed :
In outer block exception
pl/sql procedure successfully completed.
You can re-raise the exception if you want, just add
raise;
after dbms_output.put_line in the exception handler.
If you put raise; in the inner block, as well as the outer block exception, then this will be printed :
In inner block exception
In outer block exception
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 14
Hope this helps a bit.
Thanks
Amit
: if an exception is raised in one block and it does not have any exception handlres, but the enclosing block has the exeception handlers. how the exception is propogated?