From e5313d03feceacd421f5f2aeb15201aab68b81ef Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Fri, 19 Jun 2015 09:56:01 +0200 Subject: [PATCH] Fix uncaught exceptions --- fairmq/CMakeLists.txt | 2 +- fairmq/FairMQChannel.h | 2 +- fairmq/FairMQStateMachine.cxx | 78 +++++++++++++++++++++-------------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index ff027244..e6a1df63 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -141,7 +141,7 @@ install(FILES ${FAIRMQHEADERS} DESTINATION include) set(DEPENDENCIES ${DEPENDENCIES} - boost_thread boost_timer boost_system boost_program_options boost_random boost_chrono + boost_thread boost_timer boost_system boost_program_options boost_random boost_chrono boost_exception ) set(LIBRARY_NAME FairMQ) diff --git a/fairmq/FairMQChannel.h b/fairmq/FairMQChannel.h index e63cbee4..fe12c1e5 100644 --- a/fairmq/FairMQChannel.h +++ b/fairmq/FairMQChannel.h @@ -76,4 +76,4 @@ class FairMQChannel static boost::mutex channelMutex; }; -#endif /* FAIRMQCHANNEL_H_ */ \ No newline at end of file +#endif /* FAIRMQCHANNEL_H_ */ diff --git a/fairmq/FairMQStateMachine.cxx b/fairmq/FairMQStateMachine.cxx index 852c50c3..e3af1756 100644 --- a/fairmq/FairMQStateMachine.cxx +++ b/fairmq/FairMQStateMachine.cxx @@ -12,6 +12,8 @@ * @author D. Klein, A. Rybalchenko */ + +#include #include // for WaitForEndOfStateForMs() #include "FairMQStateMachine.h" @@ -96,9 +98,9 @@ bool FairMQStateMachine::ChangeState(int event) return false; } } - catch (std::exception& e) + catch (boost::exception &e) { - LOG(ERROR) << e.what(); + LOG(ERROR) << boost::diagnostic_information(e); } } @@ -109,24 +111,31 @@ bool FairMQStateMachine::ChangeState(std::string event) void FairMQStateMachine::WaitForEndOfState(int event) { - switch (event) + try { - case INIT_DEVICE: - case INIT_TASK: - case RUN: - case RESET_TASK: - case RESET_DEVICE: + switch (event) { - boost::unique_lock lock(fStateMutex); - while (!fStateFinished) + case INIT_DEVICE: + case INIT_TASK: + case RUN: + case RESET_TASK: + case RESET_DEVICE: { - fStateCondition.wait(lock); + boost::unique_lock lock(fStateMutex); + while (!fStateFinished) + { + fStateCondition.wait(lock); + } + break; } - break; + default: + LOG(ERROR) << "Requested state is either synchronous or does not exist."; + break; } - default: - LOG(ERROR) << "Requested state is either synchronous or does not exist."; - break; + } + catch (boost::exception &e) + { + LOG(ERROR) << boost::diagnostic_information(e); } } @@ -137,29 +146,36 @@ void FairMQStateMachine::WaitForEndOfState(std::string event) bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs) { - switch (event) + try { - case INIT_DEVICE: - case INIT_TASK: - case RUN: - case RESET_TASK: - case RESET_DEVICE: + switch (event) { - boost::unique_lock lock(fStateMutex); - while (!fStateFinished) + case INIT_DEVICE: + case INIT_TASK: + case RUN: + case RESET_TASK: + case RESET_DEVICE: { - fStateCondition.wait_until(lock, boost::chrono::system_clock::now() + boost::chrono::milliseconds(durationInMs)); - if (!fStateFinished) + boost::unique_lock lock(fStateMutex); + while (!fStateFinished) { - return false; + fStateCondition.wait_until(lock, boost::chrono::system_clock::now() + boost::chrono::milliseconds(durationInMs)); + if (!fStateFinished) + { + return false; + } } + return true; + break; } - return true; - break; + default: + LOG(ERROR) << "Requested state is either synchronous or does not exist."; + return false; } - default: - LOG(ERROR) << "Requested state is either synchronous or does not exist."; - break; + } + catch (boost::exception &e) + { + LOG(ERROR) << boost::diagnostic_information(e); } }