|
Boost : |
From: Bronek Kozicki (brok_at_[hidden])
Date: 2003-10-30 16:41:54
Peter Dimov <pdimov_at_[hidden]> wrote:
> Jessie Hernandez wrote:
> [...]
>> The above hierarchy, I think, is the best of both worlds: you have a
>> minimal number of exception classes covering broad types of errors.
>
> But _why_ is having a minimal number of exception classes a virtue?
Maybe just because LWG do not like to have many exception classes, and
we are striving to create something which could be accepted into future
version of standard C++ library ?
But I can see other point. This is about how exception hierachies are
being used in C++ standard library. Currently C++ standard has very few
exception classes which could be reused by all classes (runtime_error,
logic_error and family), single exception class per language domains
(bad_cast, bad_alloc, bad_exception, bad_typeid) and single exception in
whole IO part of the standard library (ios_base::failure). There is some
pattern on how exceptions are currently being used in the standard
library:
1. reuse universal exceptions
2. define single exception in your part of standard library and use it.
It's perfectly possible that I get this wrong, but it's also obvious
that C++ standard does use minimal number of exceptions classes. I do
not think that Committee would be hasty changing this. On the other
hand, I understand your point "never catch if you don't know how to
handle" (actually, I think that catch & rethrow don't quite fits here,
but you have some point and I could be wrong).
Defining even small hierarchy instead of single exception (as it is in
IO) could be no-no in the future, when (if) this library gets proposed,
but on the other hand it could get accepted, if there is really good
reason behind it. We do not know the future. Regex has two exception
classes, hopefully we will see what's Committee opinion about it.
Anyway, having small hierarchy there will be less work to be done if we
have to fix it to fit Committee requirements. Clear separation between
exception classes will help to make it minimal and consistent with
standard library.
B.
PS. I like recent proposal from Jessie Hernandez, reducing number of
exception classes to 9
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk