[問題] 拋出例外的問題
在書上讀到拋出例外,有一種是指定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
03/16 01:21, 1F
→
03/16 01:24, , 2F
03/16 01:24, 2F