• Post Reply Bookmark Topic Watch Topic
  • New Topic

uncaught exception handling  RSS feed

 
Nicole Lacoste
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Kind of a general question. Here's my situation...

I have an application that starts lots of threads that are dependent on each other (producers and consumers). If one of the threads die I want the other threads to know about it. All my threads respond to interrupts and all my threads are subclasses of a class, MyThread, that has a method which interrupts all the other threads in the same group if the thread dies from a non null throwable. Anywhere in the run of my Threads where I return, I call dying with either an exception or null.

The problem is with uncaught exceptions. There seems to be two ways to solve the problem;
1. override the uncaughtException method as


2. wrap all the code in my runs with a



What are the reasons to choose one over the other?

Thanks,

Nicole

PS one thing I noticed is that for ordinary try-catch-finally blocks the finally is called after the catch, but if I use the uncaughtException handler the order is try-finally-uncaughtException.
[ February 20, 2007: Message edited by: Nicole Lacoste ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think either works. Are you using threadGroups here?
 
Nicole Lacoste
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Yes I am using ThreadGroups (sorry if that wasn't clear), and yes both approached work. I was just wondering if there is some reason to prefer using thread groups and uncaught exceptions over try catch in the run. There might be something I just haven't thought of.

Nicole
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer method 1 since I think its a bit more clear what you are doing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!