系統exception,以及自定義例外

2021-07-07 02:58:06 字數 1010 閱讀 6614

/*

zero_divide ( 被零除)

*/ set serveroutput on

declare

pnum number;

begin

pnum := 1/0;

exception

when zero_divide then dbms_output.put_line(『1: 0不能做被除數』);

dbms_output.put_line(『2: 0不能做被除數』);

when value_error then dbms_output.put_line(『算術錯』);

when others then dbms_output.put_line(『其他例外』);

end;

/–自定義例外: 查詢50號部門的員工姓名

set serveroutput on

declare

cursor cemp is select ename from emp where deptno=50;

pename emp.ename%type;

–自定義例外

no_emp_found exception;

begin

open cemp;

–取乙個員工

fetch cemp into pename;

if cemp%notfound then

raise no_emp_found;

end if;

/* if cemp%isopen then

close no_emp_found;

end if;

*/ close cemp;

exception

when no_emp_found then dbms_output.put_line(『沒有找到員工』);

when others then dbms_output.put_line(『其他例外』);

end;

/

Exception 自定義異常

baseexception異常繼承exception 如下 package com.common.core.exception root exception of all exceptions author zhouhaitao public class baseexception extends ...

java 自定義Exception學習

最近在弄乙個登入控制,登入之後如果session中沒有登入資訊,那麼可以直接throw乙個自定義的異常,讓框架自動的接收異常,然後,在進行檢視的跳轉。遇到的問題就是,使用cglib 之後,在丟擲異常,springmvc不能接收到異常。所以最後還是換了方式。下面是乙個簡單的異常處理 created b...

自定義Exception 實戰篇

public class entityconfigurationexception exception 異常 public class exception exception 建構函式 操作結果 訊息內容 public exception opresult opr,string message ba...