Here you can find the source of invoke(Method method, Object object, Object[] args, Class
public static <T extends Exception> Object invoke(Method method, Object object, Object[] args, Class<T> exceptionToThrow) throws T
//package com.java2s; // it under the terms of the GNU Lesser General Public License as published by import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static <T extends Exception> Object invoke(Method method, Object object, Object[] args, Class<T> exceptionToThrow) throws T { try {/*from ww w.ja v a 2 s. c om*/ return method.invoke(object, args); } catch (IllegalAccessException e) { throw handleException(exceptionToThrow, e); } catch (InvocationTargetException e) { throw handleException(exceptionToThrow, e); } } private static <T extends Throwable> T handleException( Class<T> exceptionToThrow, Throwable e) { try { return exceptionToThrow.getConstructor(Throwable.class) .newInstance(e); } catch (InstantiationException e1) { throw new RuntimeException(e); } catch (IllegalAccessException e1) { throw new RuntimeException(e); } catch (InvocationTargetException e1) { throw new RuntimeException(e); } catch (NoSuchMethodException e1) { throw new RuntimeException(e); } } }