Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-09-30 20:34:01


Emil Dotchevski wrote:
> On 9/30/07, Tom Brinkman <reportbase_at_[hidden]> wrote:
>>> 3) Support for linking multiple error tags in a single expression
>>> might be useful and help in standarizing errors throughout an application.
>>>
>>> throw boost:::exception() <<
>>> boost::error_info<tag_errorno,tag_filename,tag_size,tag_width>(
>>> (1,"output.txt",100,200);
>>>> Could you clarify what you mean?
>> Well, I could do something like this:
>>
>> typedef boost::error_info<tag_errorno,
>> tag_filename,tag_size,tag_width> error_t;
>>
>> throw error_t(1,"output.txt",100,200);
>
> You probably mean:
>
> throw my_error() << error_t(1,"output.txt",100,200);
>
> In my opinion what you're describing is better accomplished like this:
>

<snip lot's of code>

It's not at all obvious why using that much boilerplate is better.

> I think it is a mistake to standardize globally on the info you want
> to stuff into the exception at the time of the throw. What if you
> detect an error condition that matches the my_error semantics
> completely, yet you don't have a file name to pass to its constructor?
> You'd find a way to make the file name available to the throw site,
> right?
>
> Instead, Boost Exception allows you to just throw my_error(), even
> though you don't have all info needed to handle it; such info can be
> added later on, as the exception bubbles up to a context where it is
> available naturally.

I see. This feature is most valuable. However, so is Tom's suggestion
and I don't think both are mutually exclusive (that is if we let go of
using the template-id 'error_info' for the latter):

     typedef boost::custom_exception<tag::
         errno,tag::filename,tag::size> file_error;

Note custom_exceptions would inherit from boost::exception. We could go
further and check the first argument for being an exception type
(directly or indirectly derived from boost::exception) to replace that
default:

     typedef boost::custom_exception< an_error ,
         tag::errno,tag::filename,tag::size> file_error;

After catching an 'an_error& e' thrown like this

     throw file_error(errno,name,size);

you can still

     e << boost::error_info<tag::more>(more);

Regards,
Tobias Schwinger
- Review Manager -


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