try finally return Exception

来源:互联网 发布:德瓦管在淘宝上叫什么 编辑:程序博客网 时间:2024/06/04 04:07
1.当finally中没有return语句时, 生成的字节码包含了对异常的处理public static int tryReturnFinally() {      int i = 0;      try {          i++;          i = i / 0;          return i;      } finally {          i++;      }  }  public static int tryReturnFinally();      descriptor: ()I      flags: ACC_PUBLIC, ACC_STATIC      Code:        stack=2, locals=3, args_size=0           0: iconst_0           1: istore_0           2: iinc          0, 1           5: iload_0           6: iconst_0           7: idiv           8: istore_0           9: iload_0          10: istore_2          11: iinc          0, 1          14: iload_2          15: ireturn          16: astore_1          17: iinc          0, 1          20: aload_1          21: athrow        Exception table:           from    to  target type               2    11    16   any        LineNumberTable:          line 11: 0          line 13: 2          line 14: 5          line 15: 9          line 17: 11          line 15: 14          line 16: 16          line 17: 17          line 18: 20        LocalVariableTable:          Start  Length  Slot  Name   Signature              2      20     0     i   I        StackMapTable: number_of_entries = 1          frame_type = 255 /* full_frame */            offset_delta = 16            locals = [ int ]            stack = [ class java/lang/Throwable ]  2.当finally中有return语句时, 生成的字节码不包含对异常的处理,仅进行finally return处理,忽略try中的return语句,忽略异常public static int tryReturnFinallyReturn() {      int i = 0;      try {          i++;          i = i / 0;          return i;      } finally {          i++;          return i;      }  }  public static int tryReturnFinallyReturn();      descriptor: ()I      flags: ACC_PUBLIC, ACC_STATIC      Code:        stack=2, locals=1, args_size=0           0: iconst_0           1: istore_0           2: iinc          0, 1           5: iload_0           6: iconst_0           7: idiv           8: istore_0           9: goto          13          12: pop          13: iinc          0, 1          16: iload_0          17: ireturn        Exception table:           from    to  target type               2    12    12   any        LineNumberTable:          line 24: 0          line 26: 2          line 27: 5          line 28: 9          line 29: 12          line 30: 13          line 31: 16        LocalVariableTable:          Start  Length  Slot  Name   Signature              2      16     0     i   I        StackMapTable: number_of_entries = 2          frame_type = 255 /* full_frame */            offset_delta = 12            locals = [ int ]            stack = [ class java/lang/Throwable ]  




0 0
原创粉丝点击