import java.io.IOException; 
public class ExceptionTest{
public static void methodA(){
throw new IOException(); 
}
public static void main (String[] args){ 
try {
methodA(); 
} catch (IOException e)  { 
System.out.println("Caught IOException"); 
} catch (Exception e)   { 
System.out.println("Caught Exception"); 
}
}

}what is the result? 
A.The code will not compile. 
B.The output is caught exception. 
C.The output is caught IOException. 
D.The program executes normally without printing a message. 结果是什么,原因??

解决方案 »

  1.   

    A
    因为IOException是checked-exception
    所以methodA()必须声明throws块
      

  2.   

    同意楼上的.既然你methodA方法里会抛出异常,那个这个方法体在声明的时候就要把异常给抛出
      

  3.   

    谢谢楼上的两位朋友那是否可以这样说:
       对于方法体中的 “非运行时异常” ,方法本身要么捕获处理,要么抛出
                     而   运行时异常   ,则无此限制,因为java的运行时系统会自动捕获并处理 
      

  4.   

    一个方法中如果抛出异常   则必须用TRY_CATCH捕获或用throws声明抛出了异常
    因此以上程序不会通过编译   
      

  5.   

    楼上的如果方法内部抛出运行时异常(似乎无意义),也一定要try,catch吗?请教?
      

  6.   

    因为IOException是checked-exception
    所以methodA()必须声明throws块
    是这样的