| Author |
Logging runtime exceptions
|
Rob Marshall
Ranch Hand
Joined: Aug 17, 2009
Posts: 30
|
|
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
Joined: Aug 17, 2009
Posts: 30
|
|
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
Joined: Aug 17, 2009
Posts: 30
|
|
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
|
 |
 |
|
|
subject: Logging runtime exceptions
|
|
|