oracle - PL\SQL Exceptions handling between functions -
i have first procedure this
procedure p1(a in varchar2) begin -- call second procedure p2(a); -- other things end;
my second procedure may have exception raise:
procedure p2(a in varchar2) lv varchar2(20); begin select '1' lv dual; if lv = '2' raise general_exception; end if; end;
my general_exception
variable global exceptions type, inside package both of procedures in.
i want catch exception in first procedure p1
avoid execution of other things.
i've tried this, no results:
procedure p1(a in varchar2) begin -- call second procedure p2(a); -- other things exception when general_exception dbms_output.put_line('error'); end;
it works me (nb. did change p2 reference parameter being passed in, rather static value of '1'!):
create or replace package test_pkg general_exception exception; procedure p1 (p_a in varchar2); end test_pkg; / create package body test_pkg procedure p2 (p_a in varchar2) begin if p_a = '2' raise general_exception; end if; end p2; procedure p1 (p_a in varchar2) begin p2(p_a); dbms_output.put_line('p2 executed sucessfully. of things.'); exception when general_exception dbms_output.put_line('error'); end p1; end test_pkg; / set serveroutput on; begin test_pkg.p1('1'); test_pkg.p1('2'); end; /
and output of running p1 procedure 2 different values was:
p2 executed sucessfully. of things. error
which expected.
Comments
Post a Comment