===== 源代码 =====
public static void main(String[] args) throws Exception {
String init = "init";
try{
String ok = "process";
}catch (RuntimeException e){
String ok = "RuntimeException";
return;
}catch (Exception e){
String ok = "Exception";
return;
}catch (Error e){
String ok = "Error";
return;
}finally {
String ok = "finally";
}
return;
}
===== 字节码 =====
关键点解释 (前面的魔数之类的就不说了)
* 异常表
* 第3行-第6行之间抛出RuntimeException异常后跳转到第12行字节码
* 第3行-第6行之间抛出Exception异常后跳转到第21行字节码
* 第3行-第6行之间抛出Error异常后跳转到第30行字节码
* 第3行-第6行之间抛出其他异常后跳转到第39行字节码
* ....
* LineNumberTable
* 用于调式时显示行号,可用开关控制编译时不生成行号
Classfile /Users/fang/Documents/test2/src/main/java/cc/SumTask.class
Last modified 2018-4-6; size 812 bytes
MD5 checksum 60f31a4a4feedbb971918879e2a977f2
Compiled from "SumTask.java"
public class SumTask
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #12.#32 // java/lang/Object."":()V
#2 = String #33 // init
#3 = String #34 // process
#4 = String #35 // finally
#5 = Class #36 // java/lang/RuntimeException
#6 = String #37 // RuntimeException
#7 = Class #38 // java/lang/Exception
#8 = String #39 // Exception
#9 = Class #40 // java/lang/Error
#10 = String #41 // Error
#11 = Class #42 // SumTask
#12 = Class #43 // java/lang/Object
#13 = Class #44 // SumTask$E
#14 = Utf8 E
#15 = Utf8 InnerClasses
#16 = Utf8
#17 = Utf8 ()V
#18 = Utf8 Code
#19 = Utf8 LineNumberTable
#20 = Utf8 main
#21 = Utf8 ([Ljava/lang/String;)V
#22 = Utf8 StackMapTable
#23 = Class #45 // "[Ljava/lang/String;"
#24 = Class #46 // java/lang/String
#25 = Class #36 // java/lang/RuntimeException
#26 = Class #38 // java/lang/Exception
#27 = Class #40 // java/lang/Error
#28 = Class #47 // java/lang/Throwable
#29 = Utf8 Exceptions
#30 = Utf8 SourceFile
#31 = Utf8 SumTask.java
#32 = NameAndType #16:#17 // "":()V
#33 = Utf8 init
#34 = Utf8 process
#35 = Utf8 finally
#36 = Utf8 java/lang/RuntimeException
#37 = Utf8 RuntimeException
#38 = Utf8 java/lang/Exception
#39 = Utf8 Exception
#40 = Utf8 java/lang/Error
#41 = Utf8 Error
#42 = Utf8 SumTask
#43 = Utf8 java/lang/Object
#44 = Utf8 SumTask$E
#45 = Utf8 [Ljava/lang/String;
#46 = Utf8 java/lang/String
#47 = Utf8 java/lang/Throwable
{
public SumTask();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return
LineNumberTable:
line 4: 0
public static void main(java.lang.String[]) throws java.lang.Exception;
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=7, args_size=1
0: ldc #2 // String init
2: astore_1
3: ldc #3 // String process
5: astore_2
6: ldc #4 // String finally
8: astore_2
9: goto 48
12: astore_2
13: ldc #6 // String RuntimeException
15: astore_3
16: ldc #4 // String finally
18: astore 4
20: return
21: astore_2
22: ldc #8 // String Exception
24: astore_3
25: ldc #4 // String finally
27: astore 4
29: return
30: astore_2
31: ldc #10 // String Error
33: astore_3
34: ldc #4 // String finally
36: astore 4
38: return
39: astore 5
41: ldc #4 // String finally
43: astore 6
45: aload 5
47: athrow
48: return
Exception table:
from to target type
3 6 12 Class java/lang/RuntimeException
3 6 21 Class java/lang/Exception
3 6 30 Class java/lang/Error
3 6 39 any
12 16 39 any
21 25 39 any
30 34 39 any
39 41 39 any
LineNumberTable:
line 11: 0
line 13: 3
line 24: 6
line 25: 9
line 14: 12
line 15: 13
line 24: 16
line 16: 20
line 17: 21
line 18: 22
line 24: 25
line 19: 29
line 20: 30
line 21: 31
line 24: 34
line 22: 38
line 24: 39
line 25: 45
line 27: 48
StackMapTable: number_of_entries = 5
frame_type = 255 /* full_frame */
offset_delta = 12
locals = [ class "[Ljava/lang/String;", class java/lang/String ]
stack = [ class java/lang/RuntimeException ]
frame_type = 72 /* same_locals_1_stack_item */
stack = [ class java/lang/Exception ]
frame_type = 72 /* same_locals_1_stack_item */
stack = [ class java/lang/Error ]
frame_type = 72 /* same_locals_1_stack_item */
stack = [ class java/lang/Throwable ]
frame_type = 8 /* same */
Exceptions:
throws java.lang.Exception
}
SourceFile: "SumTask.java"
InnerClasses:
static #14= #13 of #11; //E=class SumTask$E of class SumTask