码迷,mamicode.com
首页 > 其他好文 > 详细

finally举例

时间:2018-12-18 00:02:19      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:ati   runtime   ==   stat   turn   row   run   new   else   

private  static int test1(int x) {
        try{    
            if(x == 1){    
              throw new RuntimeException();    
            }else{    
              return x;    
            }    
          }catch(Exception e){    
            return x;    
          }finally{    
            x = x + 1;    
          }   
    }
返回值为x,x=x+1会被运算,但是先保存返回值,再运算

-------------------------------
    try{    
      if(x = 1){    
        return throw new RuntimeException();    
      }else{    
        return 1;    
      }    
    }catch(Exception e){    
      return 2;    
    }finally{    
      return 3;    
    }   

永远返回3

finally举例

标签:ati   runtime   ==   stat   turn   row   run   new   else   

原文地址:https://www.cnblogs.com/yuanfei1110111/p/10134460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!