Boost logo

Boost Users :

Subject: Re: [Boost-users] [exception] Conditional error_info addition
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2010-02-16 03:09:20


On Mon, Feb 15, 2010 at 11:22 PM, Adam Badura <abadura_at_[hidden]> wrote:
>   In my use case I throw upon error during Windows Registry manipulation.
> One of the data attached to the exception object is the path to the registry
> key on which operation failed. The problem however is that sometimes (while
> the library is still developed...) the failure is due to internal code
> error: the handle to the key is no longer valid because it was closed
> (erroneously) previously.

Is this situation a bug? If that's the case I'd do something like:

PathInfo assert_path_info( std::string const & s )
{
    assert(!s.empty());
    return PathInfo(s);
}

....
BOOST_THROW_EXCEPTION(ExceptionType() <<
   assert_path_info(getPath(hKey)));

> Can anything be done about it? Can we have some form of conditional
> error_info insertion?

template <class Info>
struct cond_info
{
    typename Info::value_type value;
    bool cond;
    cond_info( typename Info::value_type const & value, bool cond ):
        value(value), cond(cond)
    {
    }
};

template <class E,class Info>
E & operator<<( E const & e, cond_info<Info> const & x )
{
    if( x.cond )
        e << Info(x.value);
    return e;
}

....
BOOST_THROW_EXCEPTION(ExceptionType() <<
   cond_info<PathInfo>(getPath(hKey),!getPath(hKey).empty()));

Like that?

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net