debug出来的~
(public class InvocationTargetException extends ReflectiveOperationException)(下面的代码是debug跳到的部分)
/**
* Constructs a InvocationTargetException with a target exception.
*
* @param target the target exception
*/
public InvocationTargetException(Throwable target) {
super((Throwable)null); // Disallow initCause
this.target = target;
}
请问这个异常是什么原因呢?要怎么解决?
https://zhidao.baidu.com/question/452924759.html
反射调用时方法抛出异常,确保反射调用的方法逻辑正确不抛出异常即可。
本身捕获到异常会包装成这个以后了抛出,因为反射的话并不知道你本来是什么异常,可以使用以下代码还原异常:
try{
}catch(InvocationTargetException e){
throw e.getCause();
}
这样抛出的异常就是包装前的异常,或者空指针,或者自定义异常之类的了。