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