View Javadoc
1   package mockit.asm.exceptionHandling;
2   
3   import edu.umd.cs.findbugs.annotations.NonNull;
4   import edu.umd.cs.findbugs.annotations.Nullable;
5   
6   import mockit.asm.controlFlow.Label;
7   import mockit.asm.util.ByteVector;
8   
9   import org.checkerframework.checker.index.qual.NonNegative;
10  
11  /**
12   * Information about an exception handler block.
13   */
14  final class ExceptionHandler {
15      /**
16       * Beginning of the exception handler's scope (inclusive).
17       */
18      @NonNull
19      final Label start;
20  
21      /**
22       * End of the exception handler's scope (exclusive).
23       */
24      @NonNull
25      final Label end;
26  
27      /**
28       * Beginning of the exception handler's code.
29       */
30      @NonNull
31      final Label handler;
32  
33      /**
34       * Internal name of the type of exceptions handled by this handler, or <code>null</code> to catch any exceptions.
35       */
36      @Nullable
37      private final String desc;
38  
39      /**
40       * Constant pool index of the internal name of the type of exceptions handled by this handler, or <code>0</code> to
41       * catch any exceptions.
42       */
43      @NonNegative
44      private final int type;
45  
46      ExceptionHandler(@NonNull Label start, @NonNull Label end, @NonNull Label handler, @Nullable String desc,
47              @NonNegative int type) {
48          this.start = start;
49          this.end = end;
50          this.handler = handler;
51          this.desc = desc;
52          this.type = type;
53      }
54  
55      @NonNull
56      String getCatchTypeDesc() {
57          return desc == null ? "java/lang/Throwable" : desc;
58      }
59  
60      void put(@NonNull ByteVector out) {
61          out.putShort(start.position).putShort(end.position).putShort(handler.position).putShort(type);
62      }
63  }