在全球的Java异常处理程序 [英] Global Exception Handlers in Java

查看:100
本文介绍了在全球的Java异常处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个全球性的,默认的异常处理我的(安卓)手机应用程序中使用(它使用Java语法)的 Thread.setDefaultUncaughtExceptionHandler(...)呼叫。我想到的只是显示一个警告对话框适当的信息给用户的。

I am thinking of setting up a global, default Exception handler for my (Android) Mobile application(which uses Java syntax) using Thread.setDefaultUncaughtExceptionHandler(...) call. I am thinking of just displaying an Alert Dialog with appropriate message to the user.

是否有任何陷阱,注意事项和规则,一个需要遵循设置时, DefaultExceptionHandlers ?像在确认过程中被杀死,完整的堆栈跟踪写入日志的任何最佳实践等?

Are there any gotchas, caveats and rules that one needs to follow when setting DefaultExceptionHandlers? Any best practices like making sure that the process is killed, full stack trace is written to logs etc. ?

链接文档,教程等,可以抛出一些光在这是受欢迎的。

Links to documentation, tutorials etc. that can throw some light on this are welcome.

感谢。

推荐答案

  • 这个名字有点误导,因为使用这种方法将设置一个默认的异常处理程序所有主题。
  • 确保没有异常可以从您的异常处理程序被抛出。
  • 如果你正在做的图形用户界面的东西从你的异常处理程序,确保你从右边线这样做。
  • 在未捕获的异常将只把车子停在异常发生的线程,如果这也导致进程终止取决于可能运行的任何其他线程。

  • The name is a bit misleading, because using that method will set a default exception handler for all threads.
  • Make sure no exceptions can be thrown from your exception handler.
  • If you're doing GUI stuff from your exception handler, make sure you're doing it from the right thread.
  • An uncaught exception will only stop the thread where the exception took place, if that also causes the process to terminate depends on any other threads that might be running.
  • 这篇关于在全球的Java异常处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆