• Post Reply Bookmark Topic Watch Topic
  • New Topic

Centralized catch for all threads

 
vivek bawge
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posted May 03, 2001 04:17 PM
--------------------------------------------------------------------------------
Hello,
the main ui class in my project calls a method that spawns several threads. I want to know if there is a way i can put a centralized catch so that all the exceptions are caught in this.
e.g MainUI.java
..
try{
//this method spawns several threads which may throw exceptions
ProjectManager.analyze();
}catch(Throwable t){
logError("Exception" + t + "in some thread spawned by PM.analyze");
}

Thanks in advance,
Vivek

 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe try extending Thread, putting a String member variable in there, catch the exception in run and put something in the String, then test if that String is null and thrown your exception with that String as the description(?)
 
James Arendt
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to obtain what you're looking to do is take all your threads and have them part of the same ThreadGroup. If you override the ThreadGroup's uncaughtException method, any of the exceptions that get passed your try-catch's will be passed to this method. You can then simply take the error and log it, display it to a window, or whatever else.
Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!