From fc61ef3d040864bfbc18612422eb84718ee610d4 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 6 Oct 2018 11:06:35 +0200 Subject: [PATCH] Improved error handling on thread exit --- src/thread/thread.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/thread/thread.cpp b/src/thread/thread.cpp index 73fa303..e8cd5de 100644 --- a/src/thread/thread.cpp +++ b/src/thread/thread.cpp @@ -80,11 +80,27 @@ namespace fc { p->set_value(); exec(); } catch ( fc::exception& e ) { - wlog( "unhandled exception" ); - p->set_exception( e.dynamic_copy_exception() ); + if( !p->ready() ) + { + wlog( "unhandled exception" ); + p->set_exception( e.dynamic_copy_exception() ); + } + else + { // possibly shutdown? + std::cerr << "unhandled exception in thread '" << name << "'\n"; + std::cerr << e.to_detail_string( log_level::warn ); + } } catch ( ... ) { - wlog( "unhandled exception" ); - p->set_exception( std::make_shared( FC_LOG_MESSAGE( warn, "unhandled exception: ${diagnostic}", ("diagnostic",boost::current_exception_diagnostic_information()) ) ) ); + if( !p->ready() ) + { + wlog( "unhandled exception" ); + p->set_exception( std::make_shared( FC_LOG_MESSAGE( warn, "unhandled exception: ${diagnostic}", ("diagnostic",boost::current_exception_diagnostic_information()) ) ) ); + } + else + { // possibly shutdown? + std::cerr << "unhandled exception in thread '" << name << "'\n"; + std::cerr << boost::current_exception_diagnostic_information() << "\n"; + } } } ); p->wait();