[英]How to print stack trace when an error occurs during annotation processing in Java
I'm working on a Java library that has an annotation processor. 我正在使用具有注释处理器的Java库 。 To trap exceptions I wrote code similar to the following code:
为了捕获异常,我编写了类似于以下代码的代码:
public class KriptonProcessor extends AbstractProcessor {
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
try {
...
return true;
} catch (Throwable e) {
String msg = StringUtils.nvl(e.getMessage());
error(null, e.getClass().getCanonicalName() + ": " + msg);
e.printStackTrace();
}
return true;
}
}
When an exception occurs, actually it's displayed as: 发生异常时,实际上显示为:
e: error: java.lang.NullPointerException:
While I was expecting the full stack trace, useful to detect where is the problem. 当我期望完整的堆栈跟踪时,这对于检测问题出在哪里很有用。 Any ideas to accomplish this task?
有什么想法可以完成这项任务吗?
Thanks in advance. 提前致谢。
public class KriptonProcessor extends AbstractProcessor {
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
try {
...
return true;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
return true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.