在以下代码中:
import java.io.*;
import java.io.FileReader;
public class ExceptionPropagationDemo {
public static void main(String[] args){
ExceptionPropagationDemo testObject =new ExceptionPropagationDemo();
testObject.throwException1();
}
public void throwCheckedException(){
try{ //try - catch error block
BufferedReader br;
br = new BufferedReader(new FileReader("/Project1/src/employee.txt"));
} catch(FileNotFoundException e){
System.out.println("An IO exception happened and has been handled");
}
finally {
System.out.println("This block always executes.");
}
}
public void throwException2() {
throwCheckedException();
}
public void throwException1(){
throwException2();
}
}
我正在尝试捕获检查的异常并处理它。在我的情况下,它将是 FileNotFoundException,但我不知道为什么它从不运行我试图打印消息或任何其他功能的 catch 块,但它似乎跳过了。谢谢