测试异常依然执行{try..catch语句块..}的后续代码:

 private static Integer  testThrows() throws Exception{
        Integer result =null;       
        try {            
           result=1/0;
            System.out.println("try块内异常后不执行!");
        } catch (Exception e) {
            System.out.println("发生异常,执行catch!");
        }
        result=100;
        System.out.println("异常依然执行{try..catch语句块..}的后续代码!" + result);
        return result;
    }

调用以上方法:
Integer re=testThrows();
System.out.println(re.toString());

执行结果:

异常依然执行{try..catch语句块..}的后续代码

 

 

 

综上所述,try{}catch语句在发现抛出异常后会结束这一块语句的内容,而不会影响整个程序的运行。

相关文章:

  • 2021-08-23
  • 2021-04-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2021-04-06
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案