ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
来自: 《深入理解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表示,出现错误的类型不同,跳转不同。