Class CodeException

java.lang.Object
org.apache.bcel.classfile.CodeException
All Implemented Interfaces:
Cloneable, Node, Constants

public final class CodeException extends Object implements Cloneable, Node, Constants
This class represents an entry in the exception table of the Code attribute and is used only there. It contains a range in which a particular exception handler is active.
Code_attribute {
  u2 attribute_name_index;
  u4 attribute_length;
  u2 max_stack;
  u2 max_locals;
  u4 code_length;
  u1 code[code_length];
  u2 exception_table_length;
  {
    u2 start_pc;
    u2 end_pc;
    u2 handler_pc;
    u2 catch_type;
  } exception_table[exception_table_length];
  u2 attributes_count;
  attribute_info attributes[attributes_count];
}
See Also:
  • Constructor Details

    • CodeException

      Constructs a new instance from another instance.
      Parameters:
      c - Source for copying.
    • CodeException

      public CodeException(int startPc, int endPc, int handlerPc, int catchType)
      Constructs a new instance.
      Parameters:
      startPc - Range in the code the exception handler is active, startPc is inclusive while.
      endPc - is exclusive.
      handlerPc - Starting address of exception handler, that is, an offset from start of code.
      catchType - If zero the handler catches any exception, otherwise it points to the exception class which is to be caught.
  • Method Details

    • accept

      public void accept(Visitor v)
      Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
      Specified by:
      accept in interface Node
      Parameters:
      v - Visitor object.
    • copy

      public CodeException copy()
      Creates a deep copy of this object.
      Returns:
      deep copy of this object.
    • dump

      public void dump(DataOutputStream file) throws IOException
      Dumps code exception to file stream in binary format.
      Parameters:
      file - Output file stream.
      Throws:
      IOException - if an I/O error occurs.
    • getCatchType

      public int getCatchType()
      Gets the type of exception that is caught.
      Returns:
      0, if the handler catches any exception, otherwise it points to the exception class which is to be caught.
    • getEndPC

      public int getEndPC()
      Gets the exclusive end index of the region where the handler is active.
      Returns:
      Exclusive end index of the region where the handler is active.
    • getHandlerPC

      public int getHandlerPC()
      Gets the starting address of exception handler, relative to the code.
      Returns:
      Starting address of exception handler, relative to the code.
    • getStartPC

      public int getStartPC()
      Gets the inclusive start index of the region where the handler is active.
      Returns:
      Inclusive start index of the region where the handler is active.
    • setCatchType

      public void setCatchType(int catchType)
      Sets the type of exception that is caught.
      Parameters:
      catchType - the type of exception that is caught.
    • setEndPC

      public void setEndPC(int endPc)
      Sets the end of handled block.
      Parameters:
      endPc - end of handled block.
    • setHandlerPC

      public void setHandlerPC(int handlerPc)
      Sets where the actual code is.
      Parameters:
      handlerPc - where the actual code is.
    • setStartPC

      public void setStartPC(int startPc)
      Sets the start of handled block.
      Parameters:
      startPc - start of handled block.
    • toString

      public String toString()
      Gets a string representation.
      Overrides:
      toString in class Object
      Returns:
      String representation.
    • toString

      Gets a string representation with constant pool.
      Parameters:
      cp - constant pool source.
      Returns:
      String representation.
    • toString

      public String toString(ConstantPool cp, boolean verbose)
      Gets a string representation with constant pool.
      Parameters:
      cp - constant pool source.
      verbose - Output more if true.
      Returns:
      String representation.