package cn.tedu.day03;
/**
-
- 数组越界异常
- 访问了数组中不存在的索引
- ArrayIndexOutOfBoundsException
- 空指针异常
- NullPointerException
- 数组的引用没有指向对象,但是却在操作对象中的元素
-
-
- @author Administrator
*
*/
public class ArrayDemo02 {
```
public static void main(String[] args) {
int[] arr={1,3,5};
//访问数组中的元素
try {
arr=null;
//System.out.println(arr[3]);
System.out.println(arr[1]);
} catch ( NullPointerException e) {
System.out.println("发生了空指针异常");
// TODO: handle exception
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("发生了数组越界异常");
// TODO: handle exception
}catch (Exception e) {
e.printStackTrace();
}finally{//不管多少异常都能执行
System.out.println(12);
}
System.out.println(123);
```
}
}