On 2/1/22 07:48, Peter Dimov via Boost wrote:
Currently, `boost::throw_exception(x)` automatically throws an exception derived from `x` that (1) injects a boost::exception base class if there's none, and (2) injects a base class that enables boost::exception_ptr support (boost::current_exception and boost::rethrow_exception.)
This is convenient, but the downside is the amount of generated code, e.g. https://godbolt.org/z/5T8T8GEqP (422 lines) compared to https://godbolt.org/z/1zr1odf7n (36 lines.)
This is not the end of the world as this code is only generated once per exception type, not on every call to throw_exception, but it's still unpleasant to see.
It so happens that boost::exception_ptr has recently acquired the ability to work under C++11 without the need for the supporting base class, by using the standard std::exception_ptr infrastructure. So if we also remove the automatic injection of boost::exception as a base class, and ask users to derive their exceptions from it if they desire having it as a base, it's possible to simplify boost::throw_exception considerably.
I would like to ask to not do this, as this is a breaking change and I have written code (outside Boost) that relies on BOOST_THROW_EXCEPTION and boost::exception. That is, I expect that an exception thrown by BOOST_THROW_EXCEPTION triggers `catch (boost::exception& e)` handler, where I may augment it with additional info before rethrowing. I also think one could use dynamic_cast to boost::exception to the same effect, and that would also break after such a change. If some lightweight throwing mechanism is needed (of which I'm not convinced), I would prefer that to be a new API.