使用全局异常处理上的android [英] Using Global Exception Handling on android
本文介绍了使用全局异常处理上的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个例子code,或如何使用Thread.setDefaultUncaughtExceptionHandler方法的教程?基本上我想显示自定义警告对话框,无论何时抛出一个异常,在我的应用程序。是否有可能这样做吗?我知道这是一个有点棘手,以在屏幕上显示的东西,如果抛出异常在UI线程,但我不知道这个任何变通。
Is there an example code, or a tutorial on how to use the Thread.setDefaultUncaughtExceptionHandler method? Basically I'm trying to display a custom alert dialog, whenever an exception is thrown, in my application. Is it possible to do this? I know it's a little bit tricky to display something on the screen, if the exception is thrown in the ui thread but I don't know any work around for this.
最好的问候,
的Gratzi
推荐答案
基本示例的人谁来到这个页面有一个解决方案:)
Basic Example for someone who comes to this page with a solution :)
public class ChildActivity extends BaseActivity {
@SuppressWarnings("unused")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int a=1/0;
}
}
有关处理错误类别:
public class BaseActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Log.e("Alert","Lets See if it Works !!!");
}
});
}
}
这篇关于使用全局异常处理上的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文