
typedef tags<tag_file_name,tag_open_mode,tag_errno> file_err; throw my_error() << file_err(name,mode,errno);
Looks good. I wonder why my_error() is required. I wonder if a globaly static object, such as "boost::exception()" might be even cleaner and more lightweight. This would allow us to rewrite the throw statement like the following: try { throw boost::exception() << file_err(name,mode,errno); } catch(boost::exception& e) { std::cerr << e; }

Tom Brinkman wrote:
I wonder why my_error() is required. I wonder if a globaly static object, such as "boost::exception()" might be even cleaner and more lightweight. It would be against the philosophy of Boost.Exception, which is that the type of the error should be independent of the data the error carries. The idea is that the type of the exception indicates the type of the error, while all additional data is carried by the boost::exception machinery. A global boost::exception object would subvert this idea.
Oh, and you can't have just one such object, because multiple exception objects might be active (even in a single thread), and if there's only one storage area, you'd get in trouble with overriding data. Sebastian Redl

typedef tags<tag_file_name,tag_open_mode,tag_errno> file_err; throw my_error() << file_err(name,mode,errno);
Looks good.
I wonder why my_error() is required. I wonder if a globaly static object, such as "boost::exception()" might be even cleaner and more lightweight.
my_error is required so that you can catch my_error or other_error or something else. This is why I overreacted perhaps when Tobias said that boost::exception wants to be THE exception class. I feel very strongly that different failures should be reported by throwing exceptions of different types. Moreover, boost::exception makes it especially easy to classify your exception types because all of them can be empty structs; the only design the user has to come up with is a hierarchy. Emil Dotchevski
participants (3)
-
Emil Dotchevski
-
Sebastian Redl
-
Tom Brinkman