Skip to content

Commit

Permalink
Fixed bug in stack backtracing where it wasn't correctly catching sys…
Browse files Browse the repository at this point in the history
…tem_error when built as part of Boost.
  • Loading branch information
Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) committed Mar 5, 2015
1 parent ecc9f84 commit 17af207
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions include/boost/afio/detail/impl/afio.ipp
Expand Up @@ -1774,10 +1774,10 @@ BOOST_AFIO_HEADERS_ONLY_MEMFUNC_SPEC void async_file_io_dispatcher_base::complet
if(afio_exception_stack())
{
std::string originalmsg;
std::error_code ec;
asio::error_code ec;
bool is_runtime_error=false, is_system_error=false;
try { rethrow_exception(e); }
catch(const std::system_error &r) { ec=r.code(); originalmsg=r.what(); is_system_error=true; }
catch(const system_error &r) { ec=r.code(); originalmsg=r.what(); is_system_error=true; }
catch(const std::runtime_error &r) { originalmsg=r.what(); is_runtime_error=true; }
catch(...) { }
if(is_runtime_error || is_system_error)
Expand All @@ -1793,7 +1793,7 @@ BOOST_AFIO_HEADERS_ONLY_MEMFUNC_SPEC void async_file_io_dispatcher_base::complet
print_stack(buffer, i.stack);
}
if(is_system_error)
e=make_exception_ptr(std::system_error(ec, buffer.str()));
e=make_exception_ptr(system_error(ec, buffer.str()));
else
e=make_exception_ptr(std::runtime_error(buffer.str()));
}
Expand Down
12 changes: 8 additions & 4 deletions test/test_functions.hpp
Expand Up @@ -149,12 +149,15 @@ static inline void watchdog_thread(size_t timeout, std::shared_ptr<std::pair<ato
#define BOOST_AFIO_TRAP_EXCEPTIONS_IN_TEST(callable) \
try { callable; } \
catch(const BOOST_AFIO_V1_NAMESPACE::system_error &e) { std::cerr << "ERROR: unit test exits via system_error code " << e.code().value() << " (" << e.what() << ")" << std::endl; BOOST_FAIL("Unit test exits via exception"); throw; } \
catch(const std::exception &e) { std::cerr << "ERROR: unit test exits via exception (" << e.what() << ")" << std::endl; BOOST_FAIL("Unit test exits via exception"); throw; } \
catch(...) { std::cerr << "ERROR: unit test exits via unknown exception" << std::endl; BOOST_FAIL("Unit test exits via exception"); throw; }
catch(const std::exception &e) { std::cerr << "ERROR: unit test exits via exception (" << e.what() << ")" << std::endl; BOOST_FAIL("Unit test exits via exception"); throw; }
#if BOOST_AFIO_USE_BOOST_UNIT_TEST
template<class T> inline void wrap_test_method(T &t)
{
BOOST_AFIO_TRAP_EXCEPTIONS_IN_TEST(t.test_method());
BOOST_AFIO_TRAP_EXCEPTIONS_IN_TEST(t.test_method())
catch(const boost::execution_aborted &) { throw; }
catch(...) { std::cerr << "ERROR: unit test exits via unknown exception" << std::endl; throw; }
}
#endif

BOOST_AFIO_V1_NAMESPACE_END

Expand Down Expand Up @@ -240,7 +243,8 @@ CATCH_TEST_CASE(BOOST_CATCH_AUTO_TEST_CASE_NAME(__test_name), __desc)
BOOST_AFIO_V1_NAMESPACE::thread &&_watchdog) : cv(std::move(_cv)), watchdog(std::move(_watchdog)) { } \
~__deleter_t() { cv->first=true; cv->second.notify_all(); watchdog.join(); } \
} __deleter(cv, BOOST_AFIO_V1_NAMESPACE::thread(BOOST_AFIO_V1_NAMESPACE::watchdog_thread, timeout, cv)); \
BOOST_AFIO_TRAP_EXCEPTIONS_IN_TEST(__test_name ## _impl()); \
BOOST_AFIO_TRAP_EXCEPTIONS_IN_TEST(__test_name ## _impl()) \
catch(...) { std::cerr << "ERROR: unit test exits via unknown exception" << std::endl; throw; } \
} \
static void __test_name ## _impl() \

Expand Down

0 comments on commit 17af207

Please sign in to comment.