try {
Class c = bean.getClass();
Method method = c.getMethod(getMethodName(task.getTarget()), getMethodParamTypes(task.getTarget()));
method.invoke(bean, getParams(task.getTarget(),task.getParams()));
}catch(InvocationTargetException ex){
Class c = bean.getClass();
Method method = c.getMethod(getMethodName(task.getTarget()), getMethodParamTypes(task.getTarget()));
method.invoke(bean, getParams(task.getTarget(),task.getParams()));
}catch(InvocationTargetException ex){
ex.printStackTrace();
throw new RuntimeException("调用接口失败,失败原因:"+ex.getTargetException() == null ? ex.getMessage() : ex.getTargetException().getMessage());}
如题,反射的地方的代码,还是会对你的自定义异常再一次封装成反射调用失败的异常。 所以如果要得到自己自定义的异常必须要用通过ex.getTargetException()来得到