Bytebuddy拦截异常抛出

时间:2016-03-30 21:46:48

标签: java jvm byte-buddy

我想拦截异常抛出并使用bytebuddy进行记录。可能吗?如果不是那些允许我这样做的其他工具呢?

1 个答案:

答案 0 :(得分:2)

您可以使用AgentBuilder编写Java代理,在所有相关类型上使用简单的MethodDelegation拦截类:

class MyInterceptor {
  @RuntimeType
  public static Object intercept(@SuperClass Callable<?> zuper) throws Exception {
    try {
      return zuper.call();
    } catch (Throwable t) {
      // log here
      throw t;
    }
  }
}

有关如何实施代理的教程,您可以阅读this article

相关问题