我想拦截异常抛出并使用 bytebuddy 记录它。是否可以?如果不是,还有什么其他工具可以让我做到这一点?
最佳答案
您可以使用 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 .
关于java - Bytebuddy拦截异常抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36320330/