try--catch语句的catch问题

lass ExceptionTest{ 

  public static void main(String args[]){ 

   try{ 

methodA(); 

   catch(IOException e){ 

System.out.println("caught IOException"); 

   } 

   catch(Exception e){ 

   System.out.println("caught Exception"); 

    } 

  } 

}

1. If methodA() throws a IOException, what is the result?

答案:caught IOException

2.If we change the sequence of catch,what’s the result?(更换两个catch的顺序,结果如何)

答案:编译错误 

Unreachable catch block for IOException. It is already handled by the catch block for Exception


   无法到达的catch块IOException异常。他已经被IOException异常的catch块已经被处理、

如果catch要捕获的异常量是同一种异常或者存在继承关系,则要将捕获子异常放在语句最前面 ,否则编译报错



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值