Re: best pratices in Exception Handling

From: steve (me_at_me.com)
Date: 11/27/04


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!!.



Relevant Pages

  • Re: on error against try..catch
    ... This is one point where try/cast can help as you can catch only those ... exception that are of a given class. ... > in some routine like mousemove, graphical drawing etc i sometimes i use ... >>> if exception handling is better like i think how can i do to pass from ...
    (microsoft.public.dotnet.general)
  • Re: Exception as the primary error handling mechanism?
    ... handling rather than use error code. ... In the article API Design Matters by Michi Henning ... could some python expert explain to me why exception is ... Simple, when an exception is thrown and I don't catch it, the exception terminates the program immediately and I got a traceback showing the point of failure. ...
    (comp.lang.python)
  • Re: handling of errors
    ... Issue a message and don't set a return-code, ... The only reason I'm suggesting operator intervention prior to the job ... an exception and have the global exception handler write the exception, ... sense for the routine that detects the condition to "generate an exception" ...
    (bit.listserv.ibm-main)
  • Re: on error against try..catch
    ... You are allowed to do nothing when an exception is raised but I would still ... > I have converted a large vb6 program with an add-in that for every routine ... > "if myerrhandle then ON ERROR GOTO HERRHANDLER" ... > Well setting myerrhandle to true seems that the error handling keeps on ...
    (microsoft.public.dotnet.general)
  • Re: handling of errors
    ... Years ago I've convinced our CICS systems programmers to add ... This is where we dump our program traces, ... The invoked routine can only protect itself. ... exception and have the global exception handler write the exception, ...
    (bit.listserv.ibm-main)