--异常捕获
declare a number:=3;begin
a:=5/0;
exception
when ZERO_DIVIDE then
dbms_output.put_line('算术异常');
when others then
dbms_output.put_line('dd');
end;
--自定义异常
declare a number:=-3;b number:=5;
gd exception; --自定义一个异常
begin
if a<0 then
raise gd;
end if;
exception
when gd then
dbms_output.put_line('滚蛋');
when others then
dbms_output.put_line('dd');
end;
--嵌套异常
declare a number:=-3;
b number:=5;
gd exception; --自定义一个异常begin
begin
if a<0 then
raise gd;
end if;
exception
when gd then
dbms_output.put_line('滚蛋');
when others then
dbms_output.put_line('dd');
end;
a:=5/0;
exception
when ZERO_DIVIDE then
dbms_output.put_line('算术异常');
when others then
dbms_output.put_line('dd');
end;