在异常处理程序(java)中使程序崩溃

时间:2015-02-01 15:26:52

标签: android exception crash libgdx desktop

我正在制作适用于Android和台式电脑的LibGDX游戏。每当出现错误时,我都会用try/catch抓住它。这是我的工作:

try{
//Run code
}catch(Exception e){
    if(Game.isRunningOnAndroid())
        //Make application crash with error so Google can catch it and send it to my developer console
    else
        //Open error screen where desktop users can copy/paste the stack trace and send it to me
}

从上面的代码中我可以看到,我想要做的是如果游戏有错误,我想让程序崩溃,就像我没有捕获异常一样,以便错误可以在android上向我的开发者控制台报告。我该怎么做呢?有没有办法模拟错误再次崩溃程序?谢谢!

P.S。我已经编写了桌面错误屏幕,所以我不需要回答相关的问题。我只需要一种在android上运行时有目的地使程序崩溃的方法。

1 个答案:

答案 0 :(得分:1)

您可以按如下方式重新抛出原始异常:

try{
//Run code
}catch(Exception e){
    if(Game.isRunningOnAndroid())
        throw e
    else
        //Open error screen where desktop users can copy/paste the stack trace and send it to me
}
相关问题