Boost logo

Boost :

Subject: [boost] [exception] current_exception mishandling standard exceptions
From: Adam Badura (abadura_at_[hidden])
Date: 2009-05-13 13:18:54


    It seems that current_exception mishandles standard exceptions. I noted
two problems:

1)

    Some standard exceptions are not handled at all. This includes
std::runtime_error and its derived (std::overflow_error, std::range_error,
std::underflow_error), std::domain_error (handled by general
std::logic_error), std::length_error (handled by general std::logic_error)
and std::ios_base::failure (handled by general std::exception).
    Why is it so?

2)

    Non-standard exceptions derived from standard exceptions are sliced by
current_exception. It detects those types by throwing and caching and thus
will catch also derived types (like null_pointer : public
std::invalid_argument). But during construction of internal structures the
standard exception type is used and thus copy construction slices the
original exception object.
    If typeid was used instead of throwing/catching (or dynamic_cast) to
detect the type current_exception could at least detect that is will slice
the original object and use a different type so it would not pretend
everything is OK.

    Adam Badura


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