Home > Archives > JVM more-catch(多个catch)

JVM more-catch(多个catch)

Publish:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Test {
    public static void main(String[] args) {
        int x = 0;
        try {
            x = 11;
        }catch (IndexOutOfBoundsException e){
            x = 22;
        }catch (NullPointerException e){
            x = 33;
        }catch (Exception e) {
            x = 44;
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home\bin\javap -v Test
Classfile /Users/baoguo/codes/demo/target/classes/Test.class
  Last modified Mar 27, 2022; size 791 bytes
  MD5 checksum 8ad8face5c32f01e2ef5a7a2cca0b862
  Compiled from "Test.java"
public class Test
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #6.#32         // java/lang/Object."<init>":()V
   #2 = Class              #33            // java/lang/IndexOutOfBoundsException
   #3 = Class              #34            // java/lang/NullPointerException
   #4 = Class              #35            // java/lang/Exception
   #5 = Class              #36            // Test
   #6 = Class              #37            // java/lang/Object
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               LTest;
  #14 = Utf8               main
  #15 = Utf8               ([Ljava/lang/String;)V
  #16 = Utf8               e
  #17 = Utf8               Ljava/lang/IndexOutOfBoundsException;
  #18 = Utf8               Ljava/lang/NullPointerException;
  #19 = Utf8               Ljava/lang/Exception;
  #20 = Utf8               args
  #21 = Utf8               [Ljava/lang/String;
  #22 = Utf8               x
  #23 = Utf8               I
  #24 = Utf8               StackMapTable
  #25 = Class              #21            // "[Ljava/lang/String;"
  #26 = Class              #33            // java/lang/IndexOutOfBoundsException
  #27 = Class              #34            // java/lang/NullPointerException
  #28 = Class              #35            // java/lang/Exception
  #29 = Utf8               MethodParameters
  #30 = Utf8               SourceFile
  #31 = Utf8               Test.java
  #32 = NameAndType        #7:#8          // "<init>":()V
  #33 = Utf8               java/lang/IndexOutOfBoundsException
  #34 = Utf8               java/lang/NullPointerException
  #35 = Utf8               java/lang/Exception
  #36 = Utf8               Test
  #37 = Utf8               java/lang/Object
{
  public Test();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LTest;

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=3, args_size=1
         0: iconst_0
         1: istore_1
         2: bipush        11
         4: istore_1
         5: goto          26
         8: astore_2
         9: bipush        22
        11: istore_1
        12: goto          26
        15: astore_2
        16: bipush        33
        18: istore_1
        19: goto          26
        22: astore_2
        23: bipush        44
        25: istore_1
        26: return
      Exception table:
         from    to  target type
             2     5     8   Class java/lang/IndexOutOfBoundsException
             2     5    15   Class java/lang/NullPointerException
             2     5    22   Class java/lang/Exception
      LineNumberTable:
        line 3: 0
        line 5: 2
        line 12: 5
        line 6: 8
        line 7: 9
        line 12: 12
        line 8: 15
        line 9: 16
        line 12: 19
        line 10: 22
        line 11: 23
        line 13: 26
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            9       3     2     e   Ljava/lang/IndexOutOfBoundsException;
           16       3     2     e   Ljava/lang/NullPointerException;
           23       3     2     e   Ljava/lang/Exception;
            0      27     0  args   [Ljava/lang/String;
            2      25     1     x   I
      StackMapTable: number_of_entries = 4
        frame_type = 255 /* full_frame */
          offset_delta = 8
          locals = [ class "[Ljava/lang/String;", int ]
          stack = [ class java/lang/IndexOutOfBoundsException ]
        frame_type = 70 /* same_locals_1_stack_item */
          stack = [ class java/lang/NullPointerException ]
        frame_type = 70 /* same_locals_1_stack_item */
          stack = [ class java/lang/Exception ]
        frame_type = 3 /* same */
    MethodParameters:
      Name                           Flags
      args
}
SourceFile: "Test.java"

Process finished with exit code 0

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo