catch的顺序是先捕获子类异常然后再捕获父类异常,否则报错
package cn.itcast.test;
import java.util.List;
public class TryTest7 {
public static void main(String[] args) {
try {
int[] arr = {1,2,3};
System.out.println(arr[1]);
List<Integer> list = List.of(1, 2, 3);
System.out.println(list.get(4));
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
System.out.println("后续代码");
}
}