[問題] 拋出例外的問題

看板java作者 (加油)時間15年前 (2011/03/16 00:58), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/1
在書上讀到拋出例外,有一種是指定method拋出 書上範例如下 public class app13_6 { public static void aaa(int a,int b) throws ArithmeticException { int c; c=a/b; System.out.println(a+"/"+b+"="+c); } public static void main(String args[]) { try { aaa(4,0); } catch(ArithmeticException e) { System.out.println(e+" throwed"); } } } 書上說第三上要定義此method所有可能的例外,但我把throws ArithmeticException 刪除,執行結果一模一樣,那這樣定義有什麼意義呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.217.109.254

03/16 01:21, , 1F
讓人看的到她可能拋出此EXCEPTION
03/16 01:21, 1F

03/16 01:24, , 2F
不只如此 你試試看SQLEXCEPTION的範例 多包個幾層METHOD看
03/16 01:24, 2F
文章代碼(AID): #1DVvgeS6 (java)