|
Boost : |
From: Tom Brinkman (reportbase_at_[hidden])
Date: 2007-10-03 00:07:57
> 3) Support for linking multiple error tags in a single expression
> might be useful and help in standarizing errors throughout an application.
>> Could you clarify what you mean?
Lets look at boost::spirit.
Lets say that I want to throw a boost::spirit parsing exception.
Information available to me includes:
1) the filename
2) line number of error
3) charactar postion of the error
Here is how I propose that we throw the error.
struct tag_file_name: boost::error_info_value<std::string> { };
struct tag_line_number: boost::error_info_value<std::string> { };
struct tag_charactar_position : boost::error_info_value<std::string> { };
typedef boost::error_info_group<
tag_file_name,
tag_line_number,
tag_charactar_position> spirit_parsing_error_t;
int size;
std::string path;
boost::spirit::parse_info<char const*> info =
boost::spirit::parse(def.c_str(), face_grammar(path,size));
if (!info.full)
throw my_error() << spirit_parsing_error_t(
path, info.line, info.postition);
This is much cleaner and gives a standard way of throwing errors
that the spirit library generates.
Using the "<<" for an insertion operator or the "add_info"
member function just makes the throw statement look cluttered.
I dont think that they would get used because the just
look funny and non-standard.
Creating a typedef for each each error grouping is much cleaner.
Just for reference, the "<<" insertion operator would look like
this:
throw my_error() <<
boost::error_info<tag_file_name>(name) <<
boost::error_info<tag_line_number>(number) <<
boost::error_info<tag_charactar_position>(position);
This is very verbose, but minimally acceptable!!.
Also, Just for reference, the "add_info" insertion operator would look like
this:
throw my_error().add_info<tag_file_name>(name).add_info<
tag_line_number>(number).add_info<tag_charactar_position>(position);
This is too funky for me. I'd never use this syntax of "add_info"
"boost::error_info_group" would just wrap "boost::error_info" and
have defaulted template paramaters, so that if I wanted to
create an extended spirit exception, I would just do this:
throw my_error() << boost::error_info_group<tag_file_name,tag_line_number,
tag_charactar_position, error_number>(name,line,pos,error_no);
Simple!! I've already wrote the "error_info_group" wrapper if you
want me to send it to you.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk