Finally
在异常的捕获和处理过程中,finally语句的内容一定会执行
可以用来删除临时文件
FileInputStream in = null;
try{
in = new FileInputStream("myfile.txt ");
int b;
b = in.read();
while (b != -1){
System.out.print((char) b);
b = in.read();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
System.out.println(e.getMessage());
} finally{
try{
in.close();
} catch (IOException e){
e.printStackTrace();
}
}
异常总结
1.throwable及其分支图
2.五个关键词 try, catch, finally, throw (方法里面抛出异常写throw), throws(定义方法时,若需抛出异常,则添加throws)
3.catch异常的先后顺序,先catch小的异常
4.异常与重写,重写异常时要么抛出与父类相同的异常,要么不抛出异常