轻松获取堆栈跟踪
Easily get the stacktrace
在 GWT 项目中,有时我很难理解 why/when 调用了一个方法。为了弄清楚,我曾经抛出一个虚拟异常以捕获它并访问它的堆栈跟踪:
StackTraceElement[] stackTrace;
try {
throw new NullPointerException("Dummy");
} catch (NullPointerException e) {
stackTrace = e.getStackTrace();
}
它可以工作,但是为了获取堆栈跟踪而写 6 行有点乏味(+ 堆栈跟踪被虚拟异常污染了)。有没有更好的方法?
GWT.log("hi", new Exception("This is not a crash"));
在 GWT 项目中,有时我很难理解 why/when 调用了一个方法。为了弄清楚,我曾经抛出一个虚拟异常以捕获它并访问它的堆栈跟踪:
StackTraceElement[] stackTrace;
try {
throw new NullPointerException("Dummy");
} catch (NullPointerException e) {
stackTrace = e.getStackTrace();
}
它可以工作,但是为了获取堆栈跟踪而写 6 行有点乏味(+ 堆栈跟踪被虚拟异常污染了)。有没有更好的方法?
GWT.log("hi", new Exception("This is not a crash"));