JVM关键字try、catch、finally、return执行过程
关键字:jvm try catch finally return、指令
- finally相当于在所有方法返回之前执行一次
- finally中含有return其中finally中return会覆盖try和catch中的return
- 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执行过程的更多相关文章
- 异常 try catch finally return 执行关系 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- java try catch finally return执行
public static int testBasic(){ int i = 1; try{ i++; System.out.println("try block, i = "+i ...
- js中的this关键字,setTimeout(),setInterval()的执行过程
var test1 = { name: 'windseek1', showname: function () { console.log(this.name); } } var test2 = { n ...
- C++ 异常处理执行过程
看<clean code>时,又遇到异常处理的例程. 看不明白是因为我一直都将异常处理束之高阁. 今天晚上下决心去找资料看看,看完之后觉得以前是把它想得太难,其实非常简单. 希望以后遇到问 ...
- Java基础知识强化之IO流笔记06:有return的情况下try catch finally的执行顺序
1. 给出结论: (1)不管有木有出现异常,finally块中代码都会执行:(2)当try和catch中有return时,finally仍然会执行:(3)finally是在return后面的表达式运算 ...
- 【转】C# 异常处理 throw和throw ex的区别 try catch finally的执行顺序(return)
[转]throw和throw ex的区别 之前,在使用异常捕获语句try...catch...throw语句时,一直没太留意几种用法的区别,前几天调试程序时无意中了解到几种使用方法是有区别的,网上一查 ...
- jvm | 基于栈的解释器执行过程
一段简单的算术代码: public class Demo { public static void main(String[] args) { int a = 1; int b = 2; int c ...
- 小师妹学JVM之:JVM的架构和执行过程
目录 简介 JVM是一种标准 java程序的执行顺序 JVM的架构 类加载系统 运行时数据区域 执行引擎 总结 简介 JVM也叫Java Virtual Machine,它是java程序运行的基础,负 ...
- 高程(4):执行环境、作用域、上下文执行过程、垃圾收集、try...catch...
高程三 4.2.4.3 一.执行环境 1.全局执行环境是最外层的执行环境. 2.每个函数都有自己的执行环境,执行函数时,函数环境就会被推入一个当前环境栈中,执行完毕,栈将其环境弹出,把控制器返回给之前 ...
随机推荐
- idea修改maven项目版本号
1 先安装插件 2 控制台执行命令 mvn build-helper:parse-version versions:set -DnewVersion=1.1-SNAPSHOT versions:co ...
- 为什么 2020 还要学 Node.js
更佳阅读体验 https://www.yuque.com/sunluyong/node 前言 前些日子刷知乎看到个 2019 年初的问题 2019年nodejs凉了吗?凉到什么程度了?才看到问题的时候 ...
- [转] Java Agent使用详解
以下文章来源于古时的风筝 ,作者古时的风筝 我们平时写 Java Agent 的机会确实不多,也可以说几乎用不着.但其实我们一直在用它,而且接触的机会非常多.下面这些技术都使用了 Java Agent ...
- 【转载】requests库的7个主要方法、13个关键字参数以及响应对象的5种属性
Python爬虫常用模块:requests库的7个主要方法.13个关键字参数以及响应对象的5种属性 原文链接: https://zhuanlan.zhihu.com/p/67489739
- 2020年最新的过某宝滑块验证技术,Python大牛轻松搞定技术难题
致谢: Charles未晞 Charles的皮卡丘 提供解决思路,此文实为借鉴. 前言: 利用selenium模拟登录淘宝,外界传言这个确实很难过,有各种轨迹检测. 但是我没想到淘宝的滑块验证码这么容 ...
- URLDecoder异常解决方法
URLDecoder对参数进行解码时候,代码如: URLDecoder.decode(param,"utf-8"); 有时候会出现类似如下的错误: URLDecoder异常Ille ...
- three.js 着色器材质之变量(二)
上一篇郭先生在例子中用到了着色器变量中的uniform和varying.这篇继续结合例子将一下attribute变量,在使用过程中也发现由于three.js的版本迭代,之前的一些属性和参数已经发生了改 ...
- NLP Github
作者:cstghitpku链接:https://zhuanlan.zhihu.com/p/51279338来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1.分词 Wo ...
- Java 变量及运算符
Java概述 Java的发展可以归纳如下的几个阶段: (1)第一阶段(完善期):JDK 1.0 ( 1995年推出)一JDK 1.2 (1998年推出,Java更名为Java 2): (2)第二阶段( ...
- Vuex mapAction的基本使用
mapAction-store中的异步方法 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default new ...