gpt4 book ai didi

java - Bytebuddy拦截异常抛出

转载 作者:行者123 更新时间:2023-12-02 03:45:47 25 4
gpt4 key购买 nike

我想拦截异常抛出并使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com