Feature request: exception filter for Boost.Bind

Hello, world! Today I was browsing RSDN (Russian Software Developer Network) forums and found a great trick for exception handling (http://rsdn.ru/Forum/Message.aspx?mid=1420259&only=1): ============== void TheFunction() { try { ... } catch(...) { ExceptionFilter(); } } void ExceptionFilter() { try { throw; } catch(Exception1 const& e) { //Blah-blah 1 } catch(Exception2 const& e) { //Blah-blah 2 } catch(Exception3 const& e) { //Blah-blah 3 } catch(Exception4 const& e) { //Blah-blah 4 } catch(Exception5 const& e) { throw; //Just rethrow } catch(...) { //Something other } } ============== It turns out that this trick is explicitly permitted by the Standard (as it was pointed in this post: http://rsdn.ru/Forum/Message.aspx?mid=1420469&only=1). I think this trick can be really helpful in conjunction with Boost.Bind. It would be great to write something like this: ==================== boost::function<void()> func= boost::bind_with_filter(&SomeObj::func1,obj,logging_filter()); ==================== If SomeObj::func1 throws an exception then logging_filter will write it into the application's log and suppress its further propagation. Or another use-case: ==================== boost::function<void()> func=boost::bind_with_filter(&ComObject1::func,obj,com_error_translator()); ==================== com_error_translator will translate exceptions from Microsoft's _com_error to something like std::runtime_error. -- With respect, Alex Besogonov(cyberax@elewise.com)

Alex Besogonov <cyberax@elewise.com> writes:
It turns out that this trick is explicitly permitted by the Standard (as it was pointed in this post: http://rsdn.ru/Forum/Message.aspx?mid=1420469&only=1).
For what it's worth, that trick is not very portable in practice, at least not to many of the older compilers that Boost.Bind is trying to support. I suggest that instead, you do something like this: void ExceptionFilter(boost::function0<> f) { try { f(); } catch(Exception1 const& e) { //Blah-blah 1 } catch(Exception2 const& e) { //Blah-blah 2 } catch(Exception3 const& e) { //Blah-blah 3 } catch(Exception4 const& e) { //Blah-blah 4 } catch(Exception5 const& e) { throw; //Just rethrow } catch(...) { //Something other } } -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
Alex Besogonov
-
David Abrahams