/** * 异常的处理 * 1、0不可做除数 * 2、下标越界 */
//package Exception_test1;
/**
* 异常的处理
* 1、0不可做除数
* 2、下标越界
*/
public class Exception_test {
public static void main(String[] args) {
int[] a = {10, 20, 30, 40, 50};
int[] b = {0, 2, 30};
int[] c = new int[5];
for (int i = 0; i < 5; i++) {
try {
c[i] = a[i] / b[i];
} catch (ArithmeticException e) {
System.out.println("0不能做为除数!");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("数组下标越界!");
}
}
System.out.println("结束");
}
}