Jason,

I think your point is an excellent one, and it's one that I drum into the
heads of students of my PL/SQL programming class over and over. My message:
only handle and exception if you can do something about it (or to log and
re-raise it).

Mac Rinehart, President
Sextant Technology Consulting, Inc

SEXTANT TECHNOLOGY CONSULTING is a trademark of Sextant Technology
Consulting, Inc. Sextant Technology Consulting, Inc is a provider of
enterprise application development services, specializing in J2EE and Oracle
technologies. Mac Rinehart is the author of JavaServer Pages For Dummies and
Enterprise JavaBeans For Dummies.


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Jason
Dillon
Sent: Tuesday, May 14, 2002 9:35 PM
To: [EMAIL PROTECTED]
Subject: [JBoss-dev] Exception handling


I wrote Bill an example of why it is important to handle exceptions properly
which I think is useful to the group at large, so I am copying it here too
(hope that is ok Bill)

<snip>

> only find explicit handling useful when I need to do an action differently
> for each exception type.
>
> i.e.
>
> catch (SomeRecoverableException recoverable) { // do something }
> catch (Exception ex) { log.error("I'm fucked", ex); }

Right, but consider when your component with the above try/catch is nested
inside of a larger component.  With this perspective it is usually a good
idea to pass the buck... ie don't catch "I'm fucked", ex , just let it
propagate to exception handler above it.

How about a real example then?  Ok,  take MainDeployer.deploy() (and
undeploy()) which currently mask the exception thrown by the undelying
methods and components which actually do the work.

If I am a client calling MainDeployer.deploy(url) I might want to perform
some
error handling if this operation fails.  If deploy() declared that it threw
and Exception then I could write my client to gracefully handle this
case....
in fact I would be forced to handle it or pass the buck (declare it to be
thrown).

In the case of the client I might want to show a message to the user stating
why the deployment failed or I might want to try a different url...
whatever.

The point is that when you mask/eat exceptions you either make it impossible
for the calling client to detect and recover, or you make it more difficult
to determine.  In the deployer case you can call isDeployed after deploy and
see if the deployment went through, but if it did not then the client is
left
with no reason or more detail to go on further.

Exceptions are very cool as when used properly they allow you to build
simple
components and clients with hierarchacle error handling and recovery.
Consider the alternative of the shit style of error detection from c when an
error is a non-zero return value and such... what a mess.

</snip>

--jason

_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development
BEGIN:VCARD
VERSION:2.1
N:Rinehart;Mac;;President
FN:Mac Rinehart
ORG:Sextant Technology Consulting
TITLE:President
TEL;WORK;VOICE:(503) 251-2855
ADR;WORK:;;7402 SE Yamhill Street;Portland;OR;97215;USA
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:7402 SE Yamhill Street=0D=0APortland, OR 97215=0D=0AUSA
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20011008T212138Z
END:VCARD

Reply via email to