封装的异常:
- 数组下标越界异常
ArrayIndexOutOfBoundsException
如:
int[] i = new int [10];
System.out.println(i[10]);
- 空指针异常
NullPointerException
String str = null;
System.out.println(str.equals("a"));
- 算法异常
ArithmeticException
int i = 8/0;
- 类型转换异常
ClassCastException
Animal an = new Animal();
Caret cat = (Caret)an;
- 文件找不到异常
在这里插入代码片
- IO异常
在这里插入代码片
异常的处理方式:
try…catch处理方法:
- 可以使用多个catch来抛出不同的异常;
- 可以采用finally ,无论是否抛出异常都会执行其语句;