1、 若果父类中被重写的公共没有throws方式处理异常,则子类重写的公共也不能使用throws,意味着如果子类重写的公共中有异常,必须使用try-catch-finally方法处理
2、执行的方法中先后又调用了另外的几种方法,这几种方法是递进关系执行的,我们建议这几种方法使用throws的方法进行处理,而执行的方法a可以考虑使用try-catch-finally方法进行处理
public static void main(String[] args){
//方法一:
try {
method2();
}catch (IOException e){
e.printStackTrace();
}
//方法二:
//method3();//通过throws IOException已经将异常处理了
}
public static void method3() throws IOException{
try {
method2();
}catch (IOException e){
e.printStackTrace();
}
}
public static void method2() throws IOException{
method1();
}
public static void method1() throws FileNotFoundException, IOException {
File file = new File("file\\Hello.txt");
FileInputStream fis = new FileInputStream(file);
int data = fis.read();
while(data != -1){
System.out.println((char)data);
data = fis.read();
}
fis.close();
System.out.println("此为后序代码的部分......");
}