【发布时间】:2012-02-21 11:38:34
【问题描述】:
在我的应用程序类中,我试图在它发生之前捕捉一个力关闭,所以我可以记录它然后重新抛出它,以便 android 可以处理它。我这样做是因为一些用户不报告强制关闭。
我在eclipse中开发,eclipse不允许我重新抛出异常。它显示一条错误消息“未处理的异常类型 Throwable: Surround with 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();
}
}
}
【问题讨论】:
标签: android eclipse exception exception-handling