下边的代码运行后会输出什么,编译能通过吗
package cn.com.test;
public class ExceptionTest {
public static void main(String[] args){
try{
badMethod();
System.out.println("badMethod over");
}catch(RuntimeException re){
System.out.println("RuntimeException");
}catch(Exception ex){
System.out.println("other Excepiton");
}finally{
System.out.println("finally");
}
System.out.println("all over");
}
public static void badMethod(){
throw new RuntimeException();
}
public static void main(String[] args){
try{
badMethod();
System.out.println("badMethod over");
}catch(RuntimeException re){
System.out.println("RuntimeException");
}catch(Exception ex){
System.out.println("other Excepiton");
}finally{
System.out.println("finally");
}
System.out.println("all over");
}
public static void badMethod(){
throw new RuntimeException();
}
}
正确的输出结果是:
RuntimeException
finally
all over
finally
all over