现在越来越感觉Dynamic Proxy是个好东西,不过发现异常处理还是得注意下,因为调用实际的代码返回的异常都会被包一次成为InvocationTargetException,所以如果你想让原本的异常继续往上抛,那么必须捕获异常并且得到targetException然后再抛出去:
        try {
            result = targetMethod.invoke(targetObject, args);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("IllegalAccessException", e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException("IllegalArgumentException", e);
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }

(Visited 33 times, 1 visits today)