项目使用了反射进行方法调用,被调用的方法内抛出自己封装的Exception,外部无法捕捉到自定义Exception,捕捉到InvocationTargetException。
java.lang.ClassCastException: java.lang.reflect.InvocationTargetException
cannot be cast to com.test.test.exception.BaseException
public BaseResponse handleRequest(T param, Integer type) {
BaseResponse br = null;
WHMethod methodEnum = WHMethod.getByMethod(type);
String responseMsg = null;
String responseCode = null;
if (methodEnum == null) {
logger.error("未获取到需要执行的方法");
throw new BaseException(BackCode.GET_METHOD_NULL_ERROR);
}
try {
String method = methodEnum.getMethod();
Method m = this.getClass().getMethod(method, new Class[] { methodEnum.getRequestType() });
br = (BaseResponse) m.invoke(whHouseStrategy, param);
} catch (Exception e)