於指定函數拋出例外
函數名稱() throws 例外類別 { 函數中之程式碼 }
public static void abc(int a,int b) throws ArithmeticException
{
int ans;
ans=a/b;
System.out.println(a+"/"+b+"="+ans);
}try
{
abc(100,0);
}
catch(ArithmeticException e)
{
System.out.println(e+" 被拋出");
}Last updated