Re: catch all program errors...
- From: "Daniel Dyer" <dan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 21:19:35 +0100
On Wed, 31 May 2006 21:13:41 +0100, Philipp Leitner <philipp.leitner@xxxxxx> wrote:
you can simply add a Try/Catch Block to your main method:
try {
// what you usually do in main
} catch (Exception e) {
// your logging code
}
That will only work for exceptions on the main thread. To catch exceptions on all threads take a look at:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
and
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
Whether you /should/ do that is a completely different story, since you
are then surpressing severe program errors (what does not make them
less severe, but harder to detect). For example the program might throw
your NullPointerException in the middle of some transaction with the
user; then the exception is caught, and the user might never notice
that the transaction was not finished. The application might be in an
undefined error state then.
Well if these exceptions are escaping unhandled, something is broken anyway. And there is nothing stopping you from rethrowing the exception..
Dan.
--
Daniel Dyer
http://www.dandyer.co.uk
.
- Follow-Ups:
- Re: catch all program errors...
- From: tiewknvc9
- Re: catch all program errors...
- References:
- catch all program errors...
- From: tiewknvc9
- Re: catch all program errors...
- From: Philipp Leitner
- catch all program errors...
- Prev by Date: Re: Why JavaEE / EJB3?
- Next by Date: Re: How to Compile JNI program on windows/cygwin
- Previous by thread: Re: catch all program errors...
- Next by thread: Re: catch all program errors...
- Index(es):
Relevant Pages
|