Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2021-10-18 18:43:34


On Mon, Oct 18, 2021 at 6:01 AM rajesh daggumati via Boost <
boost_at_[hidden]> wrote:
>
> try
> {
> BOOST_THROW_EXCEPTION(std::invalid_argument("Blah"));
> }
> catch (...)
> {
> boost::exception_ptr exception = boost::current_exception();
> try {
> boost::rethrow_exception(exception);
> }
> catch()
> //exception is from std::invalid_argument do i need to give
> boost::excepion &e or
> std::exception &e in catch block
>
>
> My application code is having boost::exception and std::exception. I need
> a datatype to store both std::exception and boost::exception(other than
> boost::exception_ptr as everytime I need to rethrow and catch it and need
> to do everythng inside cathc block.. its not possible always)

If you can't handle the exception completely, you can rethrow the original
exception like this:

try
{
    BOOST_THROW_EXCEPTION(std::invalid_argument("Blah"));
}
catch (...)
{
    boost::exception_ptr exception = boost::current_exception();
    try {
       boost::rethrow_exception(exception);
    }
    catch( std::exception & e ) {
        ... // partially handle std::exception
        throw; // rethrow original object
    }
    catch( boost::exception & e ) {
        ... // partially handle boost::exception
        throw; // rethrow original object
    }
}


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