Class CodeException

  • All Implemented Interfaces:
    java.lang.Cloneable, Node, Constants

    public final class CodeException
    extends java.lang.Object
    implements java.lang.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:
    Code
    • Field Detail

      • EMPTY_ARRAY

        static final CodeException[] EMPTY_ARRAY
        Empty array.
      • startPc

        private int startPc
        Range in the code the exception handler.
      • endPc

        private int endPc
        Active. startPc is inclusive, endPc exclusive.
      • handlerPc

        private int handlerPc
        Starting address of exception handler, that is, an offset from start of code.
      • catchType

        private int catchType
    • Constructor Detail

      • CodeException

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

        CodeException​(java.io.DataInput file)
               throws java.io.IOException
        Constructs a new instance from a DataInput.
        Parameters:
        file - Input stream.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • 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 Detail

      • 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​(java.io.DataOutputStream file)
                  throws java.io.IOException
        Dumps code exception to file stream in binary format.
        Parameters:
        file - Output file stream.
        Throws:
        java.io.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 java.lang.String toString()
        Gets a string representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation.
      • toString

        public java.lang.String toString​(ConstantPool cp)
        Gets a string representation with constant pool.
        Parameters:
        cp - constant pool source.
        Returns:
        String representation.
      • toString

        public java.lang.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.