|
Boost : |
From: Emil Dotchevski (emil_at_[hidden])
Date: 2007-09-30 21:55:01
> <snip>
> 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;
Consider this code:
void read_file( char const * filename )
{
something_unrelated();
....
if( file_failure )
throw file_error() << error_info<tag_filename>(filename);
}
If I understand correctly, you are concerned with making sure all
file_error exceptions pack a file_name.
But what if "something_unrelated" throws? Isn't the filename known to
our function relevant to that other failure too? It sure is, despite
that we have no idea what exceptions "something_unrelated" could
throw.
So, I'd write that function like this:
void read_file( char const * filename )
{
try
{
something_unrelated();
....
if( file_failure )
throw file_error();
}
catch( boost::exception & x )
{
x << error_info<tag_filename>(filename);
throw;
}
}
How would your custom_exception idea fit in this framework?
Emil Dotchevski
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk