Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Global Exception Handlers

 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking of setting up a global, default Exception handler for my (Android) Mobile application using Thread.setDefaultUncaughtExceptionHandler(...) call. I am thinking of just displaying an Alert Dialog with appropriate message to the user.

Are there any gotchas, caveats and rules that one needs to follow when setting a 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.

Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to clean up any processes; once the uncaughtException method finishes that thread ends and the JVM will clean up as default. You could print the stack trace if you'd like to but there is no need for it. In the end, you can do whatever you want - print the exception, show a dialog*, write the exception to a log file, a combination of the previous three, anything else - as long as it doesn't throw any exceptions.

* Keep in mind to make sure to show the dialog on the Event Dispatcher Thread!
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob!
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic