关键字:jvm try catch finally return、指令

  1. finally相当于在所有方法返回之前执行一次
  2. finally中含有return其中finally中return会覆盖try和catch中的return
  3. finally中不含return时,会先将try或catch中的返回值储存在局部变量表中,最后执行返回是加载到操作数栈返回
public class FinallyReturnBean {

    public int sayGoodBye(int divide){
int c = 0;
try {
c = 1000/divide;
return c;
}catch (Exception e){
c = 500;
return c;
}finally {
c =300;
// return c;//#1 注释return c; #2 不注释 return c;
}
} public static void main(String[] args) {
System.out.println(new FinallyReturnBean().sayGoodBye( 0));
System.out.println(new FinallyReturnBean().sayGoodBye( 1));
} // #1 注释return c; 500;1000
// public class com.lsl.common.jvm.bean.FinallyReturnBean {
// public com.lsl.common.jvm.bean.FinallyReturnBean();
// Code:
// 0: aload_0
// 1: invokespecial #1 // Method java/lang/Object."<init>":()V
// 4: return // public int sayGoodBye(int);
// Code:
// 0: iconst_0
// 1: istore_2
// 2: sipush 1000
// 5: iload_1
// 6: idiv
// 7: istore_2
// 8: iload_2
// 9: istore_3 --slot3
// 10: sipush 300
// 13: istore_2
// 14: iload_3 --slot3
// 15: ireturn --1000
// 16: astore_3
// 17: sipush 500
// 20: istore_2
// 21: iload_2
// 22: istore 4
// 24: sipush 300
// 27: istore_2
// 28: iload 4
// 30: ireturn --
// 31: astore 5
// 33: sipush 300
// 36: istore_2
// 37: aload 5
// 39: athrow
// Exception table:
// from to target type
// 2 10 16 Class java/lang/Exception
// 2 10 31 any
// 16 24 31 any
// 31 33 31 any
// } // #2 不注释 return c; 300;300 try return失效
// public class com.lsl.common.jvm.bean.FinallyReturnBean {
// public com.lsl.common.jvm.bean.FinallyReturnBean();
// Code:
// 0: aload_0
// 1: invokespecial #1 // Method java/lang/Object."<init>":()V
// 4: return
//
// public int sayGoodBye(int);
// Code:
// 0: iconst_0
// 1: istore_2
// 2: sipush 1000
// 5: iload_1
// 6: idiv
// 7: istore_2
// 8: iload_2
// 9: istore_3
// 10: sipush 300
// 13: istore_2
// 14: iload_2
// 15: ireturn --
// 16: astore_3
// 17: sipush 500
// 20: istore_2
// 21: iload_2
// 22: istore 4
// 24: sipush 300
// 27: istore_2
// 28: iload_2
// 29: ireturn --
// 30: astore 5
// 32: sipush 300
// 35: istore_2
// 36: iload_2
// 37: ireturn --
// Exception table:
// from to target type
// 2 10 16 Class java/lang/Exception
// 2 10 30 any
// 16 24 30 any
// 30 32 30 any
// } }

JVM关键字try、catch、finally、return执行过程的更多相关文章

  1. 异常 try catch finally return 执行关系 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. java try catch finally return执行

    public static int testBasic(){ int i = 1; try{ i++; System.out.println("try block, i = "+i ...

  3. js中的this关键字,setTimeout(),setInterval()的执行过程

    var test1 = { name: 'windseek1', showname: function () { console.log(this.name); } } var test2 = { n ...

  4. C++ 异常处理执行过程

    看<clean code>时,又遇到异常处理的例程. 看不明白是因为我一直都将异常处理束之高阁. 今天晚上下决心去找资料看看,看完之后觉得以前是把它想得太难,其实非常简单. 希望以后遇到问 ...

  5. Java基础知识强化之IO流笔记06:有return的情况下try catch finally的执行顺序

    1. 给出结论: (1)不管有木有出现异常,finally块中代码都会执行:(2)当try和catch中有return时,finally仍然会执行:(3)finally是在return后面的表达式运算 ...

  6. 【转】C# 异常处理 throw和throw ex的区别 try catch finally的执行顺序(return)

    [转]throw和throw ex的区别 之前,在使用异常捕获语句try...catch...throw语句时,一直没太留意几种用法的区别,前几天调试程序时无意中了解到几种使用方法是有区别的,网上一查 ...

  7. jvm | 基于栈的解释器执行过程

    一段简单的算术代码: public class Demo { public static void main(String[] args) { int a = 1; int b = 2; int c ...

  8. 小师妹学JVM之:JVM的架构和执行过程

    目录 简介 JVM是一种标准 java程序的执行顺序 JVM的架构 类加载系统 运行时数据区域 执行引擎 总结 简介 JVM也叫Java Virtual Machine,它是java程序运行的基础,负 ...

  9. 高程(4):执行环境、作用域、上下文执行过程、垃圾收集、try...catch...

    高程三 4.2.4.3 一.执行环境 1.全局执行环境是最外层的执行环境. 2.每个函数都有自己的执行环境,执行函数时,函数环境就会被推入一个当前环境栈中,执行完毕,栈将其环境弹出,把控制器返回给之前 ...

随机推荐

  1. P4383 [八省联考2018]林克卡特树 树形dp Wqs二分

    LINK:林克卡特树 作为树形dp 这道题已经属于不容易的级别了. 套上了Wqs二分 (反而更简单了 大雾 容易想到还是对树进行联通情况的dp 然后最后结果总和为各个联通块内的直径. \(f_{i,j ...

  2. luogu P6583 回首过去 简单数论变换 简单容斥

    LINK:回首过去 考试的时候没推出来 原因:状态真的很差 以及 数论方面的 我甚至连除数分块都给忘了. 手玩几个数据 可以发现 \(\frac{x}{y}\)满足题目中的条件当且仅当 这个是一个既约 ...

  3. 每日一道 LeetCode (9):实现 strStr()

    每天 3 分钟,走上算法的逆袭之路. 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee ...

  4. MnasNet:Mobile Neural Architecture Search(MNAS)

  5. springboot多环境配置文件

    一.关于springboot的配置文件 springboot的配置文件主要有两种:properties文件和yml文件,我们只要选择一种使用就可以了.我们通过properties文件介绍一下配置的方式 ...

  6. C# 委托 应用实例

    用一句话解释委托:委托是一种可以把引用存储为函数的类型. 有些类似Spring框架对于接口的用法,向Action中注入Service对象.Action并不知道调用哪个服务层,只有容器通过配置文件 向A ...

  7. CSS3 新添选择器

    目录 属性选择器 结构伪类选择器 伪元素选择器 属性选择器 属性选择器可以元素特定属性来进行选择,这样就可以不借助于类选择器或id选择器 选择符 简述 E[att] 选择具有att属性的E元素 E[a ...

  8. C#LeetCode刷题之#605-种花问题( Can Place Flowers)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3724 访问. 假设你有一个很长的花坛,一部分地块种植了花,另一部 ...

  9. 如何隐藏win32 控制台程序的console窗口 2011-06-17 17:59

    加上 即可 // 隐藏窗口#pragma   comment(linker,   "/subsystem:\"windows\"  /entry:\"mainC ...

  10. 设计模式:装饰者模式介绍及代码示例 && JDK里关于装饰者模式的应用

    0.背景 来看一个项目需求:咖啡订购项目. 咖啡种类有很多:美式.摩卡.意大利浓咖啡: 咖啡加料:牛奶.豆浆.可可. 要求是,扩展新的咖啡种类的时候,能够方便维护,不同种类的咖啡需要快速计算多少钱,客 ...