Re: Real life cost of using exceptions for control flow?
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/17/04
- Next message: Jon Skeet [C# MVP]: "Re: BinaryWriter.Flush and BufferedStream.Flush"
- Previous message: Chris: "Re: BinaryWriter.Flush and BufferedStream.Flush"
- In reply to: Alvin Bruney [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Next in thread: Bruno Jouhier [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Reply: Bruno Jouhier [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Jun 2004 17:51:16 +0100
<"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:
> >Following your "never throw any exceptions" convention
> Where is it that this came from me? Can you copy and paste it in here
> please.
It seemed to be implied by you disagreeing so vociferously with my
disagreement with Bruno.
> >Do you really *never*
> > catch any exceptions raised by your own code, except at the very top
> > level?
>
> I'm confused by this. I don't know where it came from. What I am saying is
> that convention dictates that exceptions should not be used to control
> program flow.
So how does that disagree with what I said to Bruno? I said that there
are some times when the answer to "Am I doing the right thing by
raising an exception here and catching it there?" is yes.
> This is the point of the entire thread.
Interesting given that the title of the thread is about the cost of
exceptions. The cost of a reasonable number of exceptions (200 per
hour) in terms of performance is pretty low, as I've shown. The cost of
abusing exceptions in terms of code maintainability can be horrendous,
and I've never suggested otherwise.
> You are arguing that
> it really doesn't matter and that convention can be broken because
> exceptions aren't all that expensive.
No, I've never argued that it doesn't matter. I've argued that
performance isn't the main reason not to use exceptions for control
flow.
> That's wrong in principle because that sort of coding practice leads to
> unreadable, unmaintainable, inefficient code. butWhich is why bruno pointed out
> that control flow is a better approach than having exceptions determine
> flow. If you are off track on this thread, you should re-read it from the
> top again. I don't mind waiting. I got nothing else to do today.
I suggest you have a re-read yourself then.
> 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.
>
> The sum of your argument is that your machine can throw a couple thousand
> exceptions without consequence.
No, that's *not* the sum of my argument. My argument is that a couple
of thousand exceptions being thrown in an hour doesn't have much
*performance* consequence. It may well be (but isn't *necessarily*)
indicative of design flaws, however.
> These are your words, not mine.
They're not my words, actually. If they are, I'm sure you can quote the
ID of the article where I used those actual words. In particular,
you're the only one to use the word "consequence" in this thread up to
this point, as far as I can see. If you're going to go out of your way
to claim that some words are mine but not yours, at least do it
properly.
> If you cant
> see that as disturbing then this thread is pointless. By convention - which
> means not using exceptions to control code flow - natural design of code
> follows from this premise. If you designed it properly with flow, it
> wouldn't be bent out of shape in the first place. You are arguing after the
> fact which is a baseless, faulty premise.
Whereas you're arguing based on the assumption that I've said things
which I haven't.
> I've been eyeing this thread for a long while without getting involved but I
> must jump in because certain people have a greater moral responsibility than
> others.
LOL - you seem to think that having moral responsibility is the same as
agreeing with your point of view. Given that I disagree with your point
of view, don't I have just as great a moral responsibility to explain
*my* point of view?
> It often means tailoring responses for the greater good of
> programming. This *is one such case where you should be touting convention
> over your opinion because a greater good is served to everyone by siding
> with convention.
No, it's not. Blindly following *any* convention is a bad idea - it's
*always* a good idea to look at the arguments for and against any
particular convention and *then* deciding whether to follow it or not
(and how closely to follow it if you do).
> When you stand on principle like that, you lead others
> astray because you cause them to break with convention. And convention in
> this case is good.
Obviously I disagree. There is a spectrum of opinion on this, clearly.
I'm *not* advocating using exceptions all over the place as a matter of
course. I'm advocating using them carefully and appropriately, not
avoiding them completely in application code (which is what Bruno is
suggesting).
Bruno takes what I view as a fairly extreme point of view: the only
exceptions that can be thrown are essentially fatal ones, which should
be caught in a single place. I take a less restrictive view - but that
doesn't mean I'm advocating using them all over the place, which you
seem to be implying. (I generally *do* use them for things which might
be logged, and which should be recovered from - but I often have more
than one place for that, as the means of recovery depends on what
you're doing at the time.)
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Jon Skeet [C# MVP]: "Re: BinaryWriter.Flush and BufferedStream.Flush"
- Previous message: Chris: "Re: BinaryWriter.Flush and BufferedStream.Flush"
- In reply to: Alvin Bruney [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Next in thread: Bruno Jouhier [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Reply: Bruno Jouhier [MVP]: "Re: Real life cost of using exceptions for control flow?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|