Re: Real life cost of using exceptions for control flow?

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/17/04


Date: Thu, 17 Jun 2004 16:02:17 +0100


 <"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:
> > We've said before we'll have to agree to disagree on this. While the
> > answer is often "No", I don't believe it *always* is.
>
> No. Just say you are wrong on this.

What, say I'm wrong when I don't believe I am? Do you really *never*
catch any exceptions raised by your own code, except at the very top
level?

> Look how many million programmers now think its ok to throw a thousand
> exceptions per hour after reading this thread. And they'll be using your
> logic to justify it. And they should rightly be fired for it! You need to
> correct this, at least for the sake of keeping with convention.

If their simple design happens to fire a thousand exceptions in an
hour, but keeps the system working well, rather than using complicated
and error-prone logic to avoid those thousand exceptions, I don't
believe they *do* deserve to get fired.

> You may not necessarily find it wrong but programmers with less experience
> will follow blindly and produce misbehaved applications. There's a good
> reason why convention dictates a clear path forward. Programmers with a lot
> of experience who know what they are doing are free to bend the rules how
> they see fit because they understand the consequences. Inexperienced
> programmers need to follow convention untill they learn the reasons why
> convention is in place.

Could you explain how any of that goes against what I said about it
Bruno's approach *often* being the right one but not *always* being the
right one?

Following your "never throw any exceptions" convention blindly is just
as wrong as following a convention of "throw exceptions here, there and
everywhere". Code which has to bend a natural design into all kinds of
knots just to avoid ever throwing an exception is just as bad as code
which throws too many exceptions, in my view.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Real life cost of using exceptions for control flow?
    ... > catch any exceptions raised by your own code, ... that convention dictates that exceptions should not be used to control ... means not using exceptions to control code flow - natural design of code ... >> Look how many million programmers now think its ok to throw a thousand ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Real life cost of using exceptions for control flow?
    ... > that convention dictates that exceptions should not be used to control ... So how does that disagree with what I said to Bruno? ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Cobol work?
    ... Consider the common Cobol-only idiom: ... normal path through the code is clear. ... that the exceptions do not obscure the normal path ... Most experienced programmers would avoid code like ...
    (comp.lang.cobol)
  • Re: Cobol work?
    ... Here is what Steve McConnell, ... >> normal path through the code is clear. ... >> that the exceptions do not obscure the normal path ... >> exceptional programmers, for whom clarity is more important ...
    (comp.lang.cobol)
  • Re: ALTER design (Was: Code problems with Perform Thru Exit causes fall through)
    ... Perhaps with such weaknesses as maintenance programmers, ... but those rules, over time, may come to have exceptions. ... if not general-exclusionary-rule ... exclusionary rule is present, ...
    (comp.lang.cobol)