• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Centralized catch for all threads

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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(?)
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic