Re: catch all program errors...
- From: "tiewknvc9" <aotemp@xxxxxxxxxxx>
- Date: 31 May 2006 13:57:53 -0700
ok, I read about the threads and have actually worked with threads
previously.
To clarify, I have created a well rounded, well tested application. I
do not expect any errors to be thrown, however in certain instances I
am sure that it is possible, simply because I am sure that I am not
flawless.
Yet I want to be sure that the user does not continue to use a program
that is not reacting correctly, one minor error can cause the program
to react poorly in time. So I think that the way I am going to go is
to make every single one of my functions throw an Exception. This way
I can react to the problem in a case by case basis.
Unless this seems like overkill or something. It is a lot of work, but
just to be sure that something worthless (like auto-updating text) does
not cause the entire program to appear to crash.... What do you guys
think, is that a good way to approach this?
Daniel Dyer wrote:
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: Oliver Wong
- Re: catch all program errors...
- References:
- catch all program errors...
- From: tiewknvc9
- Re: catch all program errors...
- From: Philipp Leitner
- Re: catch all program errors...
- From: Daniel Dyer
- catch all program errors...
- Prev by Date: Re: How to Compile JNI program on windows/cygwin
- Next by Date: Re: catch all program errors...
- Previous by thread: Re: catch all program errors...
- Next by thread: Re: catch all program errors...
- Index(es):
Relevant Pages
|