As you said, boost::exception
does not derive from std::exception
. For the reason, check the corresponding FAQ :
Despite that virtual inheritance should be used in deriving from base exception types, quite often exception types (including the ones defined in the standard library) don't derive from std::exception
virtually.
If boost::exception
derives from std::exception
, using the enable_error_info
function with such user-defined types would introduce dangerous ambiguity which would break all catch(std::exception &)
statements.
Of course, boost::exception
should not be used to replace std::exception
as a base type in exception type hierarchies. Instead, it should be included as a virtual base, in addition to std::exception
(which should probably also be derived virtually.)
The recommendation is to have specific boost exception classes derive (virtually) from both boost::exception
and std::exception
, and not just from boost::exception
.
Some boost libraries' exceptions derive only from std::exception
(like boost::bad_lexical_cast
), some from both (like boost::xpressive::regex_error
). I don't know of one that derives only from boost::exception
though, so I'd say catching just std::exception
should catch all.
std
versions when run on an appropriate compiler, so they actually are in the same inheritance path.