try..catch

来源:互联网 发布:淘宝网成唯识论直解 编辑:程序博客网 时间:2024/06/17 21:18

如果try语句块中出现属于Exception或其子类的异常,则转到catch语句块处理。
如果try语句块中出现不属于Exception或其子类的异常,则转到finally语句块处理。
如果catch语句块中出现任何异常,则转到finally语句块处理

//Java源码public int inc(){int x;try{x=1return x;}catch(Exception e){x=2return x;}finally{x=3;}}//编译后的ByteCode字节码及异常表public int inc();Code:Stack=1,Locals=5,Args_size=10:iconst_1//try块中的x=11:istore_12:iload_1//保存x到returnValue中,此时x=13:istore 45:iconst_3//finaly块中的x=36:istore_17:iload 4//将returnValue中的值放到栈顶,准备给ireturn返回9:ireturn10:astore_2//给catch中定义的Exception e赋值,存储在Slot 2中11:iconst_2//catch块中的x=212:istore_113:iload_1//保存x到returnValue中,此时x=214:istore 416:iconst_3//finaly块中的x=317:istore_118:iload 4//将returnValue中的值放到栈顶,准备给ireturn返回20:ireturn21:astore_3//如果出现了不属于java.lang.Exception及其子类的异常才会走到这里22:iconst_3//finaly块中的x=323:istore_124:aload_3//将异常放置到栈顶,并抛出25:athrowException table:from to target type0 5 10 Class java/lang/Exception0 5 21 any10 16 21 any
原创粉丝点击