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: Robin Farine
Subject: Re: [Gnu-arch-users] Nit
Date: 21 Oct 2003 10:08:20 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

>>>>> "Tom" == Tom Lord <address@hidden> writes:

[...]

    Tom> 3) "Higher level code" catches an exception from a deeply nested call
    Tom>    to printfmt and tries to Do The Right Thing.    Congratulations, 
    Tom>    you have written spaghetti-code by violating abstraction violations 
    Tom>    left and right.

[I think you are trolling here but I cannot resist.]

Only if the "higher level code" attempts to deal with what the nested
code was trying to do. But that's not why exceptions are meant for.

The good thing with a library function raising an exception is that
while the call backtracks, intermediate callers that just ignore the
error won't hide it.

If the "highest level" application is a screen saver, then yes, who
cares if printfmt fails and a function in the call path ignores the
error. But in the context of a nuclear power plant driving software,
an intermediate function hiding an error can lead to catastrophic
results. With exceptions, it's just fine for generic library code to
let errors propagate to callers. Depending on what the application was
trying to do, it can either just ignore the exception, log an error
message, attempt to aggressively free unused resources or trigger the
"death for all in 5 minutes" alarm.

Yeah, a tla error is not life-threatening. But the principle of
dealing with an error where it's appropriate or just letting callers
deal with it suffices to motivate the use of exceptions. Deciding
where to handle what is where the difficulty resides, though.

[...]

My turn to troll a little bit. I find code that catch everything and
then re-throw (for cleanup or error logging) quite grotesque (observed
frequently in Java code, who knows why). Some languages provide
constructs, like C++ automatic objects, that allow one to deal nicely
with cleanup and object state coherency in presence of exceptions. So
yes, exception mechanisms provide an elegant tool to deal with errors
which tend to be used as a hammer to fix flies on the wall.

-- 
rnf [keeping ready for a fish-slapping session]




reply via email to

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