Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2007-09-30 04:07:55


> 1) Why cant I just throw an boost::exception object?
>
> throw boost::exception() << boost::error_info<tag_errno>(100) <<
> boost::error_info<tag_file_name>("hello");

There are two reasons:

1) This design encourages throwing different types for different
failures, which is a good programming practice

2) It protects against the following subtle error:

try
{
    foo();
}
catch( boost::exception & x )
{
    x << boost::error_info<tag_file_name>("hello");
    throw x; //should have been just throw;
}

Instead of re-throwing the original exception object by a throw
expression with no operand, we accidentally throw a new exception
object, which erases the original exception type (in the current
design of the library, this situation results in compile error.)

> 2) It might be nice to support "std::cerr << e", instead
> of requiring the use of e.what().
>
> std::cerr << e;

Yes, though I'm not big fan of operator overloading. OTOH, this can be
useful in templates, so I think it's a good idea.

> 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?

Thanks for your feedback!

Emil Dotchevski


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