http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267

--- Comment #2 from David Keller <david.keller at litchis dot fr> 2012-08-15 
02:58:33 UTC ---
  1 #include <iostream>
  2 #include <boost/system/error_code.hpp>
  3 #include <boost/system/system_error.hpp>
  4
  5
  6 namespace detail {
  7
  8 inline void throw_error(const boost::system::error_code& err)
  9 {
 10     /**
 11      * If this condition is removed, (i.e. always throw)
 12      * Then the exception will be caught!!
 13      */
 14     if ( err )
 15     {
 16         boost::system::system_error e(err);
 17         throw e;
 18     }
 19 }
 20
 21 } // namespace detail
 22
 23 /**
 24  *  This exception is not catchable !
 25  */
 26 void
 27 do_throw_bad
 28     ( void )
 29 {
 30     // Simulate a boost::asio::error
 31     detail::throw_error( boost::system::errc::make_error_code(
boost::system::errc::address_in_use ));
 32 }
 33
 34 /**
 35  *  Now the exceptions thrown becomes catchable.
 36  *  When the function lives in an anonymous namespace.
 37  */
 38 namespace {
 39
 40 void
 41 do_throw_ok
 42     ( void )
 43 {
 44     // Simulate a boost::asio::error
 45     detail::throw_error( boost::system::errc::make_error_code(
boost::system::errc::address_in_use ));
 46 }
 47
 48 } // anonymous namespace
 49 [...]

When the if condition is removed from the throw_error function, the exception
is caught!

I'll continue to simplify the case.

Reply via email to