package pkg7.pkg1;
public class Main {
public static void main(String[] args) {
System.out.println("計算開始");
int i = 10;
int j = 0 ;
int temp = 0;
//補捉錯誤
try{
//本來要執行的區段放這裡
temp = i / j;
}catch(ArithmeticException e){
System.out.println("錯誤訊息為:" + e);
System.out.println("除數不可為0 ");
}
System.out.println("兩個數字相除結果:" + temp);
System.out.println("計算結束");
}
}
計算開始
錯誤訊息為:java.lang.ArithmeticException: / by zero
除數不可為0
兩個數字相除結果:0
計算結束
文章標籤
全站熱搜
