
On 7/27/06, Oleg Abrosimov <beholder@gorodok.net> wrote:
one further improvement I see is to define simple macros to eliminate some details from client code. something like this would be appropriate:
try { throw std::logic_error("testing"); } BOOST_CATCH(my_exception_handler());
and
try { throw std::logic_error("testing"); } BOOST_CATCH_EX(exceptions, my_exception_handler());
Good suggestions. Done and done. and of course, I agree with David Abrahams that exceptions typelist
should be sorted to handle most derived first. boost::is_base_of<Base, Derived> from type_traits library can be used to achieve it.
Also a good suggestion. Until last night I wasn't sure exactly how to handle this, but I figured it out. One more idea to improve maintainability of client code:
class my_exceptions_handler { BOOST_DEFINE_EXCEPTION_HANDLER_FIRST(exception_type, exception_variable, 1) { //code here } BOOST_DEFINE_EXCEPTION_HANDLER(exception_type2, exception_variable, 1, 2) { //code here } BOOST_DEFINE_EXCEPTION_HANDLER(exception_type2, exception_variable, 2, 3) { //code here } BOOST_DEFINE_EXCEPTION_HANDLER_LAST(exception_type, exception_variable, 3) { //code here } };
These macros automatically define exceptions list eliminating last piece of code duplication. numbers are used to decorate typelist' name that is already defined.
I'm not sure that I understand the need for the _FIRST and _LAST versions of the BOOST_DEFINE_EXCEPTION_HANDLER macro. I also don't understand why I need to decorate the typelist's name. If you have some pseudocode in mind for the definitions of BOOST_DEFINE_EXCEPTION_HANDER_FIRST, BOOST_DEFINE_EXCEPTION_HANDER, and BOOST_DEFINE_EXCEPTION_HANDER_LAST I'd be happy to look into this. As it stands now there is a new version of Boost Catcher in the vault. I added the BOOST_CATCH macros and the exception sorting. Comments are welcome and encouraged. Jeremy