Exception Handling in PL/SQL-1
DECLARE
v_err_code number;
v_err_text varchar (255);
myexp Exception;
PRAGMA EXCEPTION_INIT(myexp,-2292);
N number:=10;
Y number:=0;
begin
if y=0
then
raise myexp;
else
N:=10/Y;
end if;
Exception
When myexp then
Y:=2;
N:=N/Y;
DBMS_output.put_line('zero divide exception error');
v_err_code:=SQLCODE;
v_err_text:=SQLERRM;
DBMS_output.put_line('value of N is after division is : ' || N);
DBMS_output.put_line('value of Y changed : ' || Y);
DBMS_OUTPUT.PUT_LINE(v_err_code || ' Description is ' ||v_err_text);
end;
/
DECLARE
v_err_code number;
v_err_text varchar (255);
myexp Exception;
PRAGMA EXCEPTION_INIT(myexp,-2292);
N number:=10;
Y number:=0;
begin
if y=0
then
raise myexp;
else
N:=10/Y;
end if;
Exception
When myexp then
RAISE_APPLICATION_ERROR (-20001, 'divide by zero------.');
Y:=2;
N:=N/Y;
DBMS_output.put_line('zero divide exception error');
v_err_code:=SQLCODE;
v_err_text:=SQLERRM;
DBMS_output.put_line('value of N is after division is : ' || N);
DBMS_output.put_line('value of Y changed : ' || Y);
DBMS_OUTPUT.PUT_LINE(v_err_code || ' Description is ' ||v_err_text);
end;
v_err_code number;
v_err_text varchar (255);
myexp Exception;
PRAGMA EXCEPTION_INIT(myexp,-2292);
N number:=10;
Y number:=0;
begin
if y=0
then
raise myexp;
else
N:=10/Y;
end if;
Exception
When myexp then
Y:=2;
N:=N/Y;
DBMS_output.put_line('zero divide exception error');
v_err_code:=SQLCODE;
v_err_text:=SQLERRM;
DBMS_output.put_line('value of N is after division is : ' || N);
DBMS_output.put_line('value of Y changed : ' || Y);
DBMS_OUTPUT.PUT_LINE(v_err_code || ' Description is ' ||v_err_text);
end;
/
DECLARE
v_err_code number;
v_err_text varchar (255);
myexp Exception;
PRAGMA EXCEPTION_INIT(myexp,-2292);
N number:=10;
Y number:=0;
begin
if y=0
then
raise myexp;
else
N:=10/Y;
end if;
Exception
When myexp then
RAISE_APPLICATION_ERROR (-20001, 'divide by zero------.');
Y:=2;
N:=N/Y;
DBMS_output.put_line('zero divide exception error');
v_err_code:=SQLCODE;
v_err_text:=SQLERRM;
DBMS_output.put_line('value of N is after division is : ' || N);
DBMS_output.put_line('value of Y changed : ' || Y);
DBMS_OUTPUT.PUT_LINE(v_err_code || ' Description is ' ||v_err_text);
end;