Java Method Call invokeWithoutDeclaredExceptions(Method method, Object target, Object... args)

Here you can find the source of invokeWithoutDeclaredExceptions(Method method, Object target, Object... args)

Description

invoke Without Declared Exceptions

License

Apache License

Declaration

public static Object invokeWithoutDeclaredExceptions(Method method, Object target, Object... args) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;

public class Main {
    public static Object invokeWithoutDeclaredExceptions(Method method, Object target, Object... args) {
        try {/*from  w w w  .  j  a v  a2  s.c o m*/
            return doInvoke(method, target, args);
        } catch (Throwable t) {
            throw uncheck(t);
        }
    }

    private static Object doInvoke(Method method, Object target, Object... args) throws Throwable {
        try {
            return method.invoke(target, args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }

    private static RuntimeException uncheck(Throwable t) {
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof Error) {
            throw (Error) t;
        }
        throw new UndeclaredThrowableException(t);
    }
}

Related

  1. invokeVirtual(String methodName, Object onObj, Class[] declaredArgTypes, Object... withArgs)
  2. invokeVirtual(T o, Method method, Object... pa)
  3. invokeVoid(MethodHandle mh)
  4. invokeVoidNoArgMethod(Class declaringClass, String methodName, Object instance)
  5. invokeVoidSafe(Object obj, String methodName, Class paramClass, Object param)
  6. invokeWithoutInvocationException(Method m, Object obj, Object... args)