[Chapter 13] InvocationTargetException

#

| Chapter 13 The java.lang.reflect Package |

# InvocationTargetException

## Name

InvocationTargetException

## Synopsis

Class Name:

  `java.lang.reflect.InvocationTargetException`

Superclass:

  `java.lang.Exception`

Immediate Subclasses:

  None

Interfaces Implemented:

  None

Availability:

  New as of JDK 1.1

## Description

An `InvocationTargetException` is thrown when a constructor called through `Constructor.newInstance()`, or a method called through `Method.invoke()`throws an exception. The `InvocationTargetException` encapsulates the thrown exception, which can be retrieved using `getTargetException()`.

## Class Summary

    public class java.lang.reflect.InvocationTargetException
                 extends java.lang.Exception {
      // Constructors
      protected InvocationTargetException();
      public InvocationTargetException(Throwable target);
      public InvocationTargetException(Throwable target, String s);
      // Instance Methods
      public Throwable getTargetException();
    }

## Constructors

### InvocationTargetException

#### protected InvocationTargetException()

Description

  This constructor creates an `InvocationTargetException`.

#### public InvocationTargetException(Throwable target)

Parameters

  `target`

    The exception thrown by the target constructor or method.

Description

  This constructor creates an `InvocationTargetException` around the given exception with no associated detail message.

#### public InvocationTargetException(Throwable target, String s)

Parameters

  `target`

    The exception thrown by the target constructor or method.

  `s`

    A detail message.

Description

  This constructor creates an `InvocationTargetException` around the given exception with the given detail message.

## Instance Methods

### getName

#### public Throwable getTargetException()

Returns

  The exception thrown by the target constructor or method.

Description

  This method returns the exception that was originally thrown by the constructor or method.

## Inherited Methods

Method | Inherited From | Method | Inherited From
--- | --- | --- | ---
`clone()` | `Object` | `equals(Object)` | `Object`
`fillInStackTrace()` | `Throwable` | `finalize()` | `Object`
`getClass()` | `Object` | `getLocalizedMessage()` | `Throwable`
`getMessage()` | `Throwable` | `hashCode()` | `Object`
`notify()` | `Object` | `notifyAll()` | `Object`
`printStackTrace()` | `Throwable` | `printStackTrace(PrintStream)` | `Throwable`
`printStackTrace(PrintWriter)` | `Throwable` | `toString()` | `Throwable`
`wait()` | `Object` | `wait(long)` | `Object`
`wait(long, int` | `Object` |  |

## See Also

`Constructor`, `Method`, `Throwable`

Field |  | Method