0

Recently I used a Task in one of my programs. Basically one can say that the code included in the Task is executed in another thread. An exception was thrown in that thread, however I never noticed that, because Eclipse didn't show it (at least not in the console).

So, how to make sure I am informed about the exceptions of all threads?

Thanks for any hint on this!

Update: I am wondering if there is a way that does not involve code modifications / adaptions - because one can easily forget that. Any setting in Eclipse for that?

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
  • 1
    You can set an UncaughtExceptionHandler in a Thread to catch exceptions. (I'm not aware of a Task class in Java.) – Hot Licks Apr 16 '13 at 21:52
  • Thanks guys, reflecting your answers I updated my question. – stefan.at.kotlin Apr 16 '13 at 21:54
  • Well, I would expect that the Eclipse debugger will, with appropriate settings, show you the exceptions that occur in all threads. – Hot Licks Apr 16 '13 at 21:59
  • @HotLicks: You you know how to configure Eclipse for that? I tried http://www.eclipse.org/forums/index.php/t/353989/ but that assumes you see a suspended thread in the debug view, which isn't even the case for me. – stefan.at.kotlin Apr 17 '13 at 09:06
  • No, I avoid using Eclipse as much as possible. But you very likely need to set a breakpoint in the UncaughtExceptionHandler. – Hot Licks Apr 17 '13 at 10:47

1 Answers1

0

If by saying

I am wondering if there is a way that does not involve code modifications / adaptions - because one can easily forget that.

you mean, that you could forget to code/set it for every Thread, then it is not the case.

Thread.setDefaultUncaughtExceptionHandler

is a static method, so you set it only once for the whole java application. Any uncaught exception on any thread will end up in that method.

http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html

alfonx
  • 6,936
  • 2
  • 49
  • 58