package Chapter04.process;
public class CatchException_03 {
public static void main(String[] args) {
int array[] = new int[5];
int n = 0;
for (int i = 0; i < array.length; i++) {
array[i] = i;
}
for (int i = 0; i < 10; i++) { // 该循环中可能会出现数组索引越界异常
try {
try {
n = array[i] / (i - 1); // 这里可能会出现除0异常
} catch (ArithmeticException e) {
System.out.println("0不能做被除数");
}
System.out.println(n);
} catch (IndexOutOfBoundsException e) {
System.out.println("数组索引越界");
}
}
}
}
java try…catch嵌套捕获异常的实例
5星 · 超过95%的资源 需积分: 50 116 浏览量
2010-06-18
16:30:11
上传
评论
收藏 59KB ZIP 举报
yonggan68
- 粉丝: 3
- 资源: 50
- 1
- 2
前往页