Re: best pratices in Exception Handling
From: steve (me_at_me.com)
Date: 11/27/04
- Next message: Frank Gerlach: "Really (!) correct Semaphore"
- Previous message: Frank Gerlach: "Re: Correct Semaphore Implementation in Java"
- In reply to: philippe.barthelemy_GOOGLE_at_gadz.org: "best pratices in Exception Handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 28 Nov 2004 06:05:55 +0800
On Fri, 26 Nov 2004 17:42:36 +0800, philippe.barthelemy_GOOGLE@gadz.org wrote
(in article <1101462156.781438.151030@f14g2000cwb.googlegroups.com>):
> Hi
>
> I am a rookie Java developer.
> I am looking for a guide on design and architecture in Exception
> generation and handling.
>
> I have found a lot of tutorial on the syntax, but not one on how to
> actually design a sensible Exception handling.
>
> <rant>
> ( the 'think in Java' book is a farce, it should be named 'write the
> correct syntax in Java', for instance...)
> </rant>
>
> anyone can direct me to a good tutorial ?
> TIA,
> --philippe
>
you need to look at your code.
basically consider the following:
( bad example)
you have a routine that performs some function: A
Routine B calls A
Routine C calls B
you put an exception handler in A,B,C.
your routine A causes an exception, and you catch it.
because your data is bad from A, it causes an exception in B & you catch it
Because your data is bad from B it causes an exception in C. & you catch it
Whilst this is expected, it will cause your exception to "chain" up the
execution stack, but more importantly ,if this is a GUI application , it can
cause complete failure of the program.
sometimes it is better NOT to catch an exception at the place it is caused,
but to pass it back up the execution chain, using the "Throws Exception"
keyword.
But you SHOULD always catch & report ALL EXCEPTIONS, do not ever use empty
exception blocks.
I have even seen tutorials & java ref books doing this!!.
- Next message: Frank Gerlach: "Really (!) correct Semaphore"
- Previous message: Frank Gerlach: "Re: Correct Semaphore Implementation in Java"
- In reply to: philippe.barthelemy_GOOGLE_at_gadz.org: "best pratices in Exception Handling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|