我正在尝试调试一个libgdx应用程序......显然,我在某个时候会产生一个NullPointerException,但是libgdx有一个巨大的try-catch语句可以捕获我原来的异常:
public void run () {
graphics.setVSync(graphics.config.vSyncEnabled);
try {
LwjglApplication.this.mainLoop();
} catch (Throwable t) {
if (audio != null) audio.dispose();
if (t instanceof RuntimeException)
throw (RuntimeException)t;
else
throw new GdxRuntimeException(t);
}
}
因此调试器在catch语句中停止,其中抛出了(Gdx)RuntimeException。我知道t包含原始异常,但我无法确定它来自何处。有没有办法打破产生该异常的那一行?
答案 0 :(得分:0)
未使用libgdx
进行测试,但在类似系统中您可以执行...
try {
foo.run ()
} catch (RuntimeException t) {
System.err.println ("** Caught a runtime exception.");
t.printStackTrace();
Throwable tCause = t;
while (tCause = tCause.getCause()) {
System.err.println("→ caused by:");
t.getCause.printStackTrace ();
}
}
GdxException.GdxException (Throwable)
似乎应该调用super (t)
,t
反过来应该在getCause
访问者的属性中“隐藏”{{1}}。
PS:您是否尝试过像FindBugs这样的静态分析器来定位潜在的NPE?
答案 1 :(得分:0)
如何inspecting the stacktrace并在生成NullPointerException
的地方插入断点?
答案 2 :(得分:0)