Subject: Re: [boost] [exception] current_exception mishandling standardexceptions
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-05-13 13:37:45
> 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.
What would you gain from that? If you catch(invalid_argument) you want
null_pointer to be caught; if current_exception translated it to something
else, it wouldn't be.
current_exception can store something derived from invalid_argument, but
what are the benefits of doing so? Either way, catching an invalid_argument
works, catching a null_pointer doesn't.