面试时遇到的try catch finally问题
public class test2 {
static void fun(){
try{
throw new NullPointerException();
}catch(Exception e){
System.out.println("第一个try块!");
}finally{
System.out.println("第一个finally!");
}
}
public static void main(String[] argv){
try{
fun();
}catch(Exception e){
System.out.println("第二个try块!");
}finally{
System.out.println("第二个finally!");
}
}
}
运行结果为:
第一个try块!
第一个finally!
第二个finally!
为什么主方法里的catch不执行啊?
!