PLSQL異常處理及拋出自定義異常

2021-08-20 21:45:48 字數 1198 閱讀 2265

declare

i number;

em emp%rowtype;

begin

-- i:=8/0;

-- i='aaaa';

-- select * into em from emp;

select * into em from emp where empno=1234567;

exception

when zero_divid

e then

dbms_output.put_line('除0 異常');

when value_error then

dbms_output.put_line('數值轉換異常');

when too_many_rows then

dbms_output.put_line('查詢出多行記錄,但是賦值給了rowtype記錄一行資料變數');

-- when no_data_found then

-- dbms_output.put_line('沒有找到資料異常');

when others then

dbms_output.put_line('發生了其它異常' || sqlerrm);

end;

select * from emp where empno=73691;

declare

--宣告游標

cursor vrows is select * from emp where empno=8888;   

--宣告乙個記錄型變數

vrow emp%rowtype;

--宣告乙個自定義異常

no_emp exception;  

begin

--1.開啟游標

open vrows;

--2.取資料

fetch vrows into vrow;-- 預設取第一行

--3.判斷游標是否有資料

if vrows%notfound then

raise no_emp;

end if;

close vrows;

exception

when no_emp then

dbms_output.put_line('發生了自定義的異常');

end;

pyhton拋出自定義的異常

用raise語句來引發乙個異常。異常 錯誤物件必須有乙個名字,且它們應是error或exception類的子類 下面是乙個引發異常的例子 class shortinputexception exception 自定義的異常類 def init self,length,atleast super in...

丟擲異常 自定義異常

1 try catch try catch是這之間所包含的 如果出現異常時捕獲他,並進行處理的,如果 之間有錯誤,不會影響程式繼續執行下去,程式會繼續往後執行。2 throw 是在程式中明確丟擲引發的異常,比如throw new exception 3 finally 不管有沒有異常程式段中都會被執...

如何丟擲異常,自定義異常

定義乙個方法,丟擲 陣列越界和算術異常 多個異常 用 隔開 public void test1 int x throws arrayindexoutofbound ception,arithmeticexception 資料越界異常 else if x 1 算術異常 else if x 2 publ...