一 捕获异常
1 代码
public void tryCatch() {
try {
File file = new File("d:/hello.txt");
FileInputStream fis = new FileInputStream(file);
String info = "hello!";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
2 图解
二 return 和 finally的执行顺序问题
1 代码
// 思考:如下方法返回结果为多少?
public static String func() {
String str = "hello";
try {
return str;
} finally {
str = "atguigu";
}
}
public static void main(String[] args) {
System.out.println(func()); // hello
}
2 运行结果
hello