Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-01-09 16:44:46


From: "William E. Kempf" <wekempf_at_[hidden]>
> > From: "Peter Dimov" <pdimov_at_[hidden]>
> > From: "William E. Kempf" <wekempf_at_[hidden]>
> > >
> > > OK, I've been looking at boost::filesystem_error. Here's my thoughts:
> > >
> > > boost::filesystem_error could be benefited by splitting it up into
more
> > > exception types. I know this was suggested in the review, but don't
know
> > > what the plan was in regard to this. In Boost.Threads case, so far we
> > have
> > > need for 4 different errors: lock errors, resource errors, invalid
> > arguments and
> > > unsupported errors.
> >
> > POSIX actually distinguishes out of memory errors (ENOMEM) from other
lack
> > of resource errors (EAGAIN), and POSIX functions can fail with an
"access
> > denied" error (EPERM).
>
> EPERM is not an issue (I believe) for anything in Boost.Threads (yet).

But won't it become relevant when you add the thread attributes?

MSDN doesn't really say whether it's possible to get ERROR_ACCESS_DENIED
from thread functions but I wouldn't rule out the possibility. :-)

> But this doesn't really answer my basic question. Is it better to carry
these
> error codes in a single exception, or have multiple exception types?

I believe I answered this question below. No, it is not better to lump the
different errors into a single exception. Separate exceptions are fine.

> (And is it useful to distinguish between memory and other resource
errors?)

This, I have no ready answer for... but "when in doubt, do what POSIX does."

> > If the reason for the failure can be identified by the type of the
> > exception, there should be no immediate need to carry an OS error code,
> > although you should consider the "how do I translate this to a localized
> > error message" problem.
>
> Any suggestions on that one? I haven't really seen any viable answers
provided yet.

The easiest is to simply return e.g. "boost::thread_resource_error" from
what(), but it might prove controversial. :-)

> > No, this would be a step backward. IIUC filesystem_error is expected to
> > evolve into a hierarchy as exception categories of interest to callers
are
> > identified.
>
> Then why *ever* carry the OS error code. The exception type would likely
> mirror every OS error code possible (with some folding, where appropriate,
where
> I'd expect the precise code to be irrelevant). I don't understand what
the OS
> error code would add.

An error code (OS or portable) can be of help when one needs to catch all
thread-related (or better yet, all error code providing) exceptions in a
single catch clause. Usually this is only needed to report an error, though,
so if thread exceptions provide some other common mechanism to identify the
error (like specific what() values), carrying an error code won't be
necessary.


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