java异常机制-----------try_catch

package cn.zxg.Exception;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
* try_catch_finally捕获异常
*/

public class Test02 {
public static void main(String[] args) {
//一个try可以包含多个catch
FileReader reader=null;

try {
reader= new FileReader("D:\\a.txt");
char c1=(char)reader.read();
System.out.println(c1);
} catch (FileNotFoundException e) {//子类异常在父类异常前面
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}


}

}
posted on 2019-05-23 07:00  zz测试笔记  阅读(309)  评论(0编辑  收藏  举报