如果一个拦截器抛出异常,则预测行为

问题描述

假设我定义了2个MethodInterceptor,例如I1和I2。

public class I1 implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        if (someConditionIsTrue) {
           throw new MyException();
        }
        Object value = methodInvocation.proceed();
        System.out.println("I1 after");
        return value;
    }
}

public class I2 implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        System.out.println("I2 before");
        Object value = methodInvocation.proceed();
        System.out.println("I2 after");
        return value;
    }
}

假设这两个拦截器都应用相同的方法,并且I1首先由Guice执行,但会引发异常,第二个拦截器会发生什么情况?

  1. 将由guice执行I2还是将其完全跳过。
  2. 在对methodInvocation.proceed()进行调用之前,I2是否会部分执行?
  3. 还是将I2完全执行,而与其余拦截器发生什么无关?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)