首页 > 编程语言 > 详细

【java】try,catch,finally 各种情况是否被执行到

时间:2021-01-20 15:11:59      阅读:20      评论:0      收藏:0      [点我收藏+]

 

finally会被执行到

1.catch中 throw

       try{
           int i = 1/0;
       }catch (Exception e) {
           throw e;

       }finally {
           System.out.println("finally");
       }    

技术分享图片

 

 

2.catch中return

    try{
           int i = 1/0;
       }catch (Exception e) {
           return;

       }finally {
           System.out.println("finally");
       }

 

 

 

 

 

finally不会被执行到

1.catch中退出程序

    try{
           int i = 1/0;
       }catch (Exception e) {
           System.exit(1);

       }finally {
           System.out.println("finally");
       }

 

【java】try,catch,finally 各种情况是否被执行到

原文:https://www.cnblogs.com/sxdcgaq8080/p/14302388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!