公司项目中使用了Java的反射,通过反射执行别人的方法时候抛出了一个“java.lang.reflect.InvocationTargetException”的异常,百度了一下看的云里雾里的。
查看Java手册的解释是:InvocationTargetException 是一种包装由调用方法或构造方法所抛出异常的经过检查的异常。依然是很难理解。
因为涉及到跨组调试等问题,只能继续Google。最终还是在stackoverflow看到一个比较靠谱的解释“From the Javadoc of Method.invoke()
Throws: InvocationTargetException - if the underlying method throws an exception.
This exception is throw if the method called threw an exception.
”,应该是因为反射执行的方法里抛出了异常造成的。