libgdx捕获所有异常,只显示RuntimeException而不是原始异常

时间:2013-08-27 14:27:52

标签: java libgdx

我正在尝试调试一个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包含原始异常,但我无法确定它来自何处。有没有办法打破产生该异常的那一行?

3 个答案:

答案 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)

这是有效的解决方案:将t中显示的异常添加到应始终触发调试器的异常列表中,即使被捕获也是如此:

Break when exception is thrown

感谢您的帮助:)