|
Boost : |
From: William Kempf (sirwillard_at_[hidden])
Date: 2000-08-11 17:53:25
--- In boost_at_[hidden], "Reid Sweatman" <borderland_at_u...> wrote:
> > -----Original Message-----
> > From: David Abrahams [mailto:abrahams_at_m...]
> > Sent: Friday, August 11, 2000 6:05 AM
> > To: boost_at_[hidden]
> > Subject: Re: [boost] Re: Threads by Jeremy and Monitors in one?
>
> > "Expectedness" is a poor measure of whether an exception is the
> > appropriate
> > response, IMO. In some sense, any error you can write recovery
code for is
> > "expected". The criterion to use is "will the caller almost
certainly want
> > to handle the condition locally, or is stack unwinding more
> > likely to be the
> > desired behavior?"
>
> Okay, I'll buy that...but I'll have to think about it a bit. It's
not the
> criterion I was taught to use. But I'm aware that there's more
than one
> school of thought on when to use exceptions, and what you say makes
sense,
> except that there's often legitimate uses for exceptions that don't
involve
> stack unwinding and in which the exception is handled locally. Me
go back
> to hut and make sacrifice; maybe understand in morning <g>.
No matter what school of thought you follow there may be a valid
reason to throw an exception here. I'm still on the fence, but I'll
illustrate why an exception may be appropriate:
void foo::bar()
{
mutex::trylock lock(mx);
// We forget to check if we locked and proceed to access
// shared resources here!
}
Using an exception will make a lot of code harder to deal with,
especially since failing to lock isn't really an exceptional
condition here, but not using an exception could lead to disaster.
The only good thing is that it shouldn't be too likely that someone
would fail to check the lock here, since they used a trylock instead
of a simple lock.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk