gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Nit


From: Mark A. Flacy
Subject: Re: [Gnu-arch-users] Nit
Date: Tue, 21 Oct 2003 03:51:48 -0500

>>>>> "Robin" == Robin Farine <address@hidden> writes:
Robin> 

[good exception useage information deleted]

Robin> My turn to troll a little bit. I find code that catch everything and
Robin> then re-throw (for cleanup or error logging) quite grotesque
Robin> (observed frequently in Java code, who knows why). 

Because many authors will think that their software layer should throw
certain exceptions and only those exceptions.  We've beaten into most of
our designers that if you aren't going to do anything with the exception
other than re-throw it, don't catch the damned thing.  That's a runtime
cost for no purpose.

We also frown upon catch, emit log, and re-throw.  Odds are very good that
someone above is going to catch, emit log, and do something
useful. (Assuming that someone above you in the call stack doesn't also do
the catch, emit log, and re-throw trick...)  Multiple logs for the same
error isn't very useful either, as long as the "does something useful"
handler prints the stack trace for truly unexpected exceptions.  

Java programmers should never catch Exception, print nothing and do nothing
with the exception.  Bad idea.

Robin> Some languages provide constructs, like C++ automatic objects, that
Robin> allow one to deal nicely with cleanup and object state coherency in
Robin> presence of exceptions. So yes, exception mechanisms provide an
Robin> elegant tool to deal with errors which tend to be used as a hammer
Robin> to fix flies on the wall.

Like looping through an array and stopping when you catch the
NoSuchElementException?

Off topic...

If you are programming in C++, I'd suggest Scott Meyer's books:

Effective C++          
More Effective C++
Effective STL


-- 
 Mark A. Flacy
 Any opinions expressed above are my own.  Any facts expressed above
 would imply that I know what I'm writing about.  Sometimes, I do!
"There's a lot to be said for a blow to the head" -- B.O.C.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]