来自:
《深入理解java虚拟机》(第一版)page161
```
public int inc(){
int x;
try{
x=1;
return x;
}catch(Exception e){
x=2;
return x;
}finally{
x=3;
}
}
//编译后的ByteCode字节码以及异常表
public int inc();
Code:
Stack=1,Locals=5;Args_size=1
0: iconst_1 //try块中的x=1
1: istrote_1
2: iload_1 //保存x到returnValue中,此时x=1
3: istore 4
5: iconst_3 //finally块中的x=3
6: istore_1
7: iload 4 //将returnValue中的值放到栈顶,准备给ireturn返回
9: ireturn
10: astore_2 //给catch中定义的Exception e赋值,存储在Slot 2中
11: iconst_2 //catch块中的x=2
12: istore_1
13: iload_1 //保存x到returnValue中,此时x=2
14: istore 4
16: iconst_3 //finally块中x=3
17: istore_1
18: iload 4 //将returnValue中的值放到栈顶,准备给ireturn返回
20: ireturn
21: astore_3
22: iconst_3
23: istore_1
24: aload_3 //将异常放置到栈顶,并抛出
25: athrow
Exception table:
from to target type
0 5 10 Class java/lang/Exception
0 5 10 any
10 16 21 any
```
最后的Exception table:
from 表示开始代码函数,to表示结尾代码行数,两个组成一个范围。
target表示,出错的时候,跳转到什么哪一行运行
type表示,出现错误的类型不同,跳转不同。
- 参考资料
- 容器的实现
- ArrayList、LinkedList与Vector的区别
- Map,Set,List,Queue,Stack的特点与用法
- HashMap的实现
- HashMap和ConcurrentHashMap差别
- HashMap和HashTable的区别
- fast fail
- java 实用方法
- Collections中实用的函数
- ArrayList中实用的函数
- Integer和Character
- Properties类的简单使用
- XML实用解析
- 从jar包中读取文件信息
- java自带base64加密解密
- java机制
- 分派
- 反射
- 类加载机制
- java中一个对象的初始化
- 泛型
- 自动装箱,拆箱与遍历循环
- 偏向于语法
- new int[]
- new boolean[]
- Switch能否用string做参数
- equals与==的区别
- 泛型对象数组
- Enum的用法
- String、StringBuffer与StringBuilder的区别
- try catch finally
- finalize方法
- object有哪些公用方法
- Java的四种引用,强弱软虚,用到的场景
- java访问修饰符
- Hashcode的作用
- 九种基本数据类型
- java对象大小
- 数组长度
- 动态代理的一个例子
- java.lang.NoClassDefFoundError
- ThreadLocal