• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Logging runtime exceptions

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I apologize if this has already been asked, but I wasn't sure what to search for...

I'm writing an application (my first one in Java, yeah! ) that uses dozens of classes spread over several files, etc. Normally the application will be run from a menu with no one sitting at the console watching it, so I need to be able to have all exception stack traces for any runtime exceptions, anything not already accounted for by a "catch", sent to a log file. Is there an easy way to make sure that any uncaught runtime exceptions will be "magically" caught and sent to the logs?

It's OK if the program exits, but I don't want to be stuck in a situation where the program dies without leaving some clues as to what happened.

I assume that I could just put a catch block like the following in every class:

but since I don't know when/where it will happen, I'd prefer to be able to set this up in one place and have it work for all the classes/files. Is that possible?

Thanks,

Rob
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found: Thread.setUncaughtExceptionHandler(), but that's as of 1.5. My code will be running on 1.4.2...

How was this done prior to 1.5?

Thanks,

Rob
 
Rob Marshall
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, it looks like the answer is to use ThreadGroup and uncaughtException, here's a simple example of something I found and modified slightly:


Rob
 
If you're gonna buy things, buy this thing and I get a fat kickback:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic