Code example for InvocationTargetException

Methods: getTargetException

  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");
      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 
Experience pair programming with AI  Get Codota for Java