package day01;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Exception1 {
public static void start() throws IOException, RuntimeException {
throw new RuntimeException("Not able to start");
}
public static void main(String args[]) {
BufferedReader br = null;
try {
String line;
br = new BufferedReader(new FileReader("\\home\\usr\test.java"));
while ((line = br.readLine()) != null) start();
return;
} catch (Exception ex) {
ex.printStackTrace();
} catch (RuntimeException re) {
re.printStackTrace();
} finally {
//是否会输出?
System.out.print(1);
}
}
}
请问:上述代码都存在哪些问题?
- start方法不会发生IOException,所以不需要throws
- RuntimeException不需要显示throws
- catch的时候要从子类开始catch
- 没有关闭流
- return之前finally块是会执行的