Boost logo

Boost :

From: Matthew Herrmann (matthew.herrmann_at_[hidden])
Date: 2006-11-15 17:54:20


>
> Message: 9
> Date: Tue, 14 Nov 2006 18:06:03 -0800
> From: "Emil Dotchevski" <emildotchevski_at_[hidden]>
> Subject: Re: [boost] Review Request: Boost Exception
> To: <boost_at_[hidden]>
> Message-ID: <BAY125-DAV966A5057842FC29C1782BD4EA0_at_phx.gbl>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> reply-type=original
>
>> >
>> > No, that's not quite what I meant.
>> >
>> > void tag_exception(boost::exception& x)
>> > {
>> > // do something to x
>> > }
>> >
>> > void read_file()
>> > {
>> > boost::adorn_exception e( boost::bind( tag_exception, _1 ) );
>> > ...
>> > }
>>
>
> Could you provide more detail on the "do something to x" part? It seems to
> me that it would require something similar to the boost::exception::pimpl
> class, in that it must be able to store arbitrary values, but unlike
> boost::exception::pimpl it would have to keep some kind of proxy for each
> stored object, to be evaluated later if something throws.
>
> Wouldn't that amount to executing a lot of code and using a lot of storage,
> even if nothing throws?
Here's how it would work:

> void tag_exception(boost::exception& x, std::string* filename)
> {
> // append filename tag to exception here
> }
>
> void read_file(const std::string& filename)
> {
> boost::adorn_exception e( boost::bind( tag_exception, _1, &filename) );
> ...
> }

There is a (small) fixed cost of creating the functor for boost::bind
and copying the pointer. By using pointers (or references, though the
syntax is heavier), you avoid hidden copy-construction costs. Since
boost::adorn_exception has to be declared after the variables it refers
to, the pointers will still be valid when it is destroyed.

Regards,
Matthew Herrmann


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