Boost logo

Boost :

From: Reid Sweatman (borderland_at_[hidden])
Date: 2000-08-13 07:31:51


> -----Original Message-----
> From: David Abrahams [mailto:abrahams_at_[hidden]]
> Sent: Friday, August 11, 2000 8:07 PM
> To: boost_at_[hidden]
> Subject: [boost] Exception usage (was: Threads by Jeremy and Monitors in
> one?)

> I don't think so. Just consider the behavior you want, and all
> will be well.
> When I programmatically detect a bug in my code, a.k.a violation of
> precondition, I want the program to stop at the point of
> detection, and give
> me an opportunity to inspect the exact program state. Once a
> precondition is
> violated, I have little faith in any error-recovery efforts that might be
> achieved through stack-unwinding: as far as I'm concerned, the
> program state
> is corrupted, and some whole-program invariant has been violated.

I went over the sections on exceptions in Stroustrup 3rd last night, and I
think I understand what you're saying now. That does seem a more
intelligent way to use exceptions than the limited form I've been using. I
still think I would use them for local problems involving more than a few
lines of code, just for consistency's sake. Yes, a broken precondition
should be fatal, whereas a class-invariant problem may not be. It now seems
to me that the exception mechanism is more a method of signalling safely up
the call chain, than just an error-handler (without working like signals, of
course), so I guess any reasonable usage that keeps the program running
without too much of a performance penalty, or shuts it down when something
fatal happens is okay to do. Should have looked at Stroustrup to begin
with; I read the 2nd edition a couple of times way back when, but acquired
the 3rd during a high-stress period, and didn't immediately form the habit
of checking it first. I have probably too much tendency to use the C++ FAQ
2nd; that's where I got my original ideas on exceptions.

> > I'm beginning to understand why some people here aren't too gung ho on
> > exceptions to begin with.
>
> I don't understand that last bit.

I was just referring to the arguments that have gone on sporadically in the
past here about throw decorations. It's mostly concerned empty
specifications, but there were some arguments against using them at all. I
didn't mean that anyone here considered them unusable; it's just difficult
to know when an exception mechanism is the way to handle a problem. But
thanks to your explanation, I think I have a better handle on it now.
Thanks.

Reid Sweatman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk