在我的Application类中,我试图在发生强制关闭之前捕获它,这样我就可以记录下来,然后重新抛出它,以便Android系统处理。我这么做是因为有些用户不报告强制关闭。
我在使用Eclipse开发时,它不允许我重新抛出异常。它显示一个错误,提示“未处理的异常类型Throwable:用try/catch包围”。那我怎么才能重新抛出异常呢?
我在使用Eclipse开发时,它不允许我重新抛出异常。它显示一个错误,提示“未处理的异常类型Throwable:用try/catch包围”。那我怎么才能重新抛出异常呢?
public class MainApplication extends Application
{
@Override
public void onCreate()
{
super.onCreate();
try
{
//Log exception before app force closes
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
AnalyticsUtils.getInstance(MainApplication.this).trackEvent(
"Errors", // Category
"MainActivity", // Action
"Force Close: "+ex.toString(), // Label
0); // Value
AnalyticsUtils.getInstance(MainApplication.this).dispatch();
Toast.makeText(MainApplication.this, "Snap! Something broke. Please report the Force Close so I can fix it.", Toast.LENGTH_LONG);
//rethrow the Exception so user can report it
//throw ex; //<-- **eclipse is showing an error to surround with try/catch**
}
});
} catch (Exception e)
{
e.printStackTrace();
}
}
}