Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: PACKAGEs; exception propagation

Re: PACKAGEs; exception propagation

From: Andy Hassall <andy_at_andyh.org>
Date: Sat, 08 Jun 2002 13:02:36 +0100
Message-ID: <l6s3gu8ff3smi3u1s5nrophc6g9sgi2hh3@4ax.com>


On Sat, 8 Jun 2002 11:49:13 +0200, "ronald" <ronald_at_foo.com> wrote:

>Second question: according to Oracle docs, when an exception is raised, and
>if PL/SQL cannot find a handler, the exception propagates. That is, "the
>exception reproduces itself in successive enclosing blocks until a handler
>is found or there are no more blocks to search. In the latter case, PL/SQL
>returns an UNHANDLED EXCEPTION error to the host environment".
>
>Now, if I have procedure P1 which calls procedure P2, can I propagate
>exceptions raised in P2 to P1, and not to host environment? If not,
>can somebody recommend some guidelines for dealing with sets of procedures
>and functions which call each other? Scratch tables?
>Functions returning status? Seems pretty primitive to me.

 The procedures back up the call stack are surrounding blocks, and the exceptions propagate to them. It's only when you get back to the top level that it comes out as ORA-06510: PL/SQL: unhandled user-defined exception.

create or replace package ajhexceptiontest as

   procedure p1;
   procedure p2;
   e_exp exception;
end ajhexceptiontest;
/
create or replace package body ajhexceptiontest as
  procedure p1 is
  begin
    p2();
  exception
    when e_exp then
      dbms_output.put_line('Exception e_exp caught in p1');   end p1;

  procedure p2 is
  begin

     dbms_output.put_line('Raising exception e_exp in p2');
     raise e_exp;

  end p2;  

end ajhexceptiontest;
/

Package created.

Package body created.

SQL> show errors
No errors.

SQL> execute ajhexceptiontest.p2;
Raising exception e_exp in p2
BEGIN ajhexceptiontest.p2; END;

*
ERROR at line 1:

ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "TEST.AJHEXCEPTIONTEST", line 14
ORA-06512: at line 1

SQL> execute ajhexceptiontest.p1;
Raising exception e_exp in p2
Exception e_exp caught in p1

-- 
Andy Hassall (andy@andyh.org) icq(5747695) http://www.andyh.org
http://www.andyhsoftware.co.uk/space | disk usage analysis tool
Received on Sat Jun 08 2002 - 07:02:36 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US