Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-15 08:54:14


David Abrahams wrote:

> void tag_exception(boost::exception& x)
> {
> // do something to x
> }
>
> void read_file()
> {
> boost::adorn_exception e( boost::bind( tag_exception, _1 ) );
> ...
> }

This could work, if you find a way to write ~adorn_exception. You'd have

void tag_exception( boost::exception & x, std::string const & fn )
{
    x << error_info<tag_errno>( errno );
    x << error_info<tag_filename>( fn );
}

void read_file( std::string const & fn )
{
    boost::adorn_exception e( boost::bind( tag_exception, _1, boost::ref(
fn ) ) );

    // do something that can throw

    e.dismiss();
}

instead of the straightforward

void read_file( std::string const & fn )
{
    try
    {
        // do something that can throw
    }
    catch( boost::exception & x )
    {
        x << error_info<tag_errno>( errno );
        x << error_info<tag_filename>( fn );
        throw;
    }
}

I prefer the second.


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