public class Demo01 {
public static void main(String[] args) {
int divisor=100;
int dividend=0;
//System.out.println(divisor/dividend);//.ArithmeticException 算術(shù)異常
try {
System.out.println(divisor/dividend);//.ArithmeticException 算術(shù)異常
}catch (Exception e){
e.printStackTrace();
System.out.println("捕獲到一個(gè)異常");
}finally {
System.out.println("不管如何都會(huì)執(zhí)行這里的代碼");
}
System.out.println("哈哈哈");
}
public class Demo02 {
public static void main(String[] args) {
int[] a=new int[2];
Scanner scanner=new Scanner(System.in);
int i=scanner.nextInt();
int j= scanner.nextInt();
try {
a[0]=i;
a[2]=j;
System.out.println(a[0]/a[2]);
//Array Index OutOf Bounds Exception 數(shù)組 索引 超出 邊界 異常
//Input Mismatch Exception 輸入 不匹配 異常
// Arithmetic Exception 數(shù)學(xué)數(shù)字 異常
}catch (ArrayIndexOutOfBoundsException | InputMismatchException | ArithmeticException e){
System.out.println("數(shù)組越界異常");
System.out.println("數(shù)據(jù)格式不正確異常");
System.out.println("算術(shù)異常");
System.out.println("以上異常中的一個(gè)");
}
}
}
Array Index OutOf Bounds Exception 數(shù)組 索引 超出 邊界 異常
Input Mismatch Exception 輸入 不匹配 異常
Arithmetic Exception 數(shù)學(xué)數(shù)字 異常