5

This question may sound a little silly ;)

How would approach the possibility of an uncaught exception within the UncaughtExceptionHandler?

mibollma
  • 14,959
  • 6
  • 52
  • 69
  • Does it mean that you have on UncaughtExceptionHandler and now you want to handle Uncaught exceptions within that handler? – Naved Aug 30 '11 at 09:14

2 Answers2

5

Very interesting question, I haven't thought about this before.

The approch seems to be that either set your own uncaughtExceptionHandler on your thread or it will get passed to JAVAs defaultUncaughtExceptionHandler,

I made some quick googeling and found a similar case for getting crash data from android. I think you may be intresing in this link How do I obtain crash-data from my Android application?

Community
  • 1
  • 1
  • 2
    The question was more like what happens if you try to shutdown a component in case of an uncaught exception inside the uncaught exception handler and that component throws an exception too. – mibollma Aug 30 '11 at 09:37
4

Well, you have to catch them yourself. The documentation of uncaughtException() linked by you states this clearly:

Any exception thrown by this method will be ignored by the Java Virtual Machine.

But you can only plan so far. So you handle the exceptions of your exception handler but who handles that code? It's the same with logging a failed logging event. Exception handlers all the way down...

musiKk
  • 14,751
  • 4
  • 55
  • 82
  • 1
    Hmm that's strange. When i tested it on Android it seemed to loop when i threw an exception on purpose. Guess it's some kind of Android bug. – mibollma Aug 30 '11 at 09:41
  • 1
    It looped for me too when I introduced a bug, er I mean "tested" it on, I believe, IBM AIX. – Joseph Gordon Oct 24 '11 at 19:00
  • @mibollma, Is Android a standard JVM? – Pacerier Jul 18 '14 at 12:09
  • @Pacerier I don't think it's going through the Java standardization process. However in this case it's more likely that it was a bug as the android documentation states almost the same behaviour: http://d.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html#uncaughtException%28java.lang.Thread,%20java.lang.Throwable%29 – mibollma Jul 18 '14 at 13:53
  • @mibollma, Weird, I'm getting the same behavior on "normal" JVMs: http://stackoverflow.com/q/24834702/632951 – Pacerier Jul 19 '14 at 03:20