Code example for InvocationTargetException

Methods: getTargetException

0
   */ 
  public Object invokeOptionalWithoutCheckedException(T target, Object... args) {
    try { 
      return invokeOptional(target, args);
    } catch (InvocationTargetException e) {
      Throwable targetException = e.getTargetException();
      if (targetException instanceof RuntimeException) {
        throw (RuntimeException) targetException;
      } 
      AssertionError error = new AssertionError("Unexpected exception");
      error.initCause(targetException);
      throw error;
    } 
  } 
 
  /** 
   * Invokes the method on {@code target} with {@code args}. Throws an error if the method is not 
   * supported. See also {@link #invokeWithoutCheckedException(Object, Object...)}. 
   * 
   * @throws IllegalArgumentException if the arguments are invalid