# Class CodeExceptionGen

java.lang.Object
org.apache.bcel.generic.CodeExceptionGen

All Implemented Interfaces:
  `Cloneable, InstructionTargeter`

public final class CodeExceptionGen extends Object implements InstructionTargeter, Cloneable
This class represents an exception handler, i.e., specifies the region where a handler is active and an instruction where the actual handling is done. pool as parameters. Opposed to the JVM specification the end of the handled region is set to be inclusive, i.e. all instructions between start and end are protected including the start and end instructions (handles) themselves. The end of the region is automatically mapped to be exclusive when calling getCodeException(), i.e., there is no difference semantically.

See Also:
  - `MethodGen`
  - `CodeException`
  - `InstructionHandle`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CodeExceptionGen(InstructionHandle startPc, InstructionHandle endPc, InstructionHandle handlerPc, ObjectType catchType)`
  Add an exception handler, i.e., specify region where a handler is active and an instruction where the actual handling is done.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `boolean`
  `containsTarget(InstructionHandle ih)`
  Tests whether this targeter targets the specified instruction handle.
  `ObjectType`
  `getCatchType()`
  Gets the type of the Exception to catch, 'null' for ANY.
  `CodeException`
  `getCodeException(ConstantPoolGen cp)`
  Gets CodeException object.
  This relies on that the instruction list has already been dumped to byte code or that the 'setPositions' methods has been called for the instruction list.
  `InstructionHandle`
  `getEndPC()`
  `InstructionHandle`
  `getHandlerPC()`
  `InstructionHandle`
  `getStartPC()`
  `void`
  `setCatchType(ObjectType catchType)`
  Sets the type of the Exception to catch.
  `void`
  `setEndPC(InstructionHandle endPc)`
  `void`
  `setHandlerPC(InstructionHandle handlerPc)`
  `void`
  `setStartPC(InstructionHandle startPc)`
  `String`
  `toString()`
  `void`
  `updateTarget(InstructionHandle oldIh, InstructionHandle newIh)`
  Replaces the target of this targeter from this old handle to the new handle.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### CodeExceptionGen

    public CodeExceptionGen(InstructionHandle startPc, InstructionHandle endPc, InstructionHandle handlerPc, ObjectType catchType)
    Add an exception handler, i.e., specify region where a handler is active and an instruction where the actual handling is done.
    Parameters:
      `startPc` - Start of handled region (inclusive)
      `endPc` - End of handled region (inclusive)
      `handlerPc` - Where handling is done
      `catchType` - which exception is handled, null for ANY

- ## Method Details

  - ### clone

    public Object clone()
    Overrides:
      `clone` in class `Object`

  - ### containsTarget

    public boolean containsTarget(InstructionHandle ih)
    Description copied from interface: `InstructionTargeter`
    Tests whether this targeter targets the specified instruction handle.
    Specified by:
      `containsTarget` in interface `InstructionTargeter`
    Parameters:
      `ih` - the instruction handle to test.
    Returns:
      true, if ih is target of this handler

  - ### getCatchType

    public ObjectType getCatchType()
    Gets the type of the Exception to catch, 'null' for ANY.

  - ### getCodeException

    public CodeException getCodeException(ConstantPoolGen cp)
    Gets CodeException object.
    This relies on that the instruction list has already been dumped to byte code or that the 'setPositions' methods has been called for the instruction list.
    Parameters:
      `cp` - constant pool

  - ### getEndPC

    public InstructionHandle getEndPC()
    Returns:
      end of handled region (inclusive)

  - ### getHandlerPC

    public InstructionHandle getHandlerPC()
    Returns:
      start of handler

  - ### getStartPC

    public InstructionHandle getStartPC()
    Returns:
      start of handled region (inclusive)

  - ### setCatchType

    public void setCatchType(ObjectType catchType)
    Sets the type of the Exception to catch. Set 'null' for ANY.

  - ### setEndPC

    public void setEndPC(InstructionHandle endPc)

  - ### setHandlerPC

    public void setHandlerPC(InstructionHandle handlerPc)

  - ### setStartPC

    public void setStartPC(InstructionHandle startPc)

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### updateTarget

    public void updateTarget(InstructionHandle oldIh, InstructionHandle newIh)
    Description copied from interface: `InstructionTargeter`
    Replaces the target of this targeter from this old handle to the new handle.
    Specified by:
      `updateTarget` in interface `InstructionTargeter`
    Parameters:
      `oldIh` - old target, either start or end
      `newIh` - new target