Fix uncaught exceptions

This commit is contained in:
Alexey Rybalchenko 2015-06-19 09:56:01 +02:00
parent d6a413534a
commit e5313d03fe
3 changed files with 49 additions and 33 deletions

View File

@ -141,7 +141,7 @@ install(FILES ${FAIRMQHEADERS} DESTINATION include)
set(DEPENDENCIES set(DEPENDENCIES
${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) set(LIBRARY_NAME FairMQ)

View File

@ -76,4 +76,4 @@ class FairMQChannel
static boost::mutex channelMutex; static boost::mutex channelMutex;
}; };
#endif /* FAIRMQCHANNEL_H_ */ #endif /* FAIRMQCHANNEL_H_ */

View File

@ -12,6 +12,8 @@
* @author D. Klein, A. Rybalchenko * @author D. Klein, A. Rybalchenko
*/ */
#include <boost/exception/all.hpp>
#include <boost/chrono.hpp> // for WaitForEndOfStateForMs() #include <boost/chrono.hpp> // for WaitForEndOfStateForMs()
#include "FairMQStateMachine.h" #include "FairMQStateMachine.h"
@ -96,9 +98,9 @@ bool FairMQStateMachine::ChangeState(int event)
return false; 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) void FairMQStateMachine::WaitForEndOfState(int event)
{ {
switch (event) try
{ {
case INIT_DEVICE: switch (event)
case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
{ {
boost::unique_lock<boost::mutex> lock(fStateMutex); case INIT_DEVICE:
while (!fStateFinished) case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
{ {
fStateCondition.wait(lock); boost::unique_lock<boost::mutex> 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."; catch (boost::exception &e)
break; {
LOG(ERROR) << boost::diagnostic_information(e);
} }
} }
@ -137,29 +146,36 @@ void FairMQStateMachine::WaitForEndOfState(std::string event)
bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs) bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs)
{ {
switch (event) try
{ {
case INIT_DEVICE: switch (event)
case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
{ {
boost::unique_lock<boost::mutex> lock(fStateMutex); case INIT_DEVICE:
while (!fStateFinished) case INIT_TASK:
case RUN:
case RESET_TASK:
case RESET_DEVICE:
{ {
fStateCondition.wait_until(lock, boost::chrono::system_clock::now() + boost::chrono::milliseconds(durationInMs)); boost::unique_lock<boost::mutex> lock(fStateMutex);
if (!fStateFinished) 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; default:
break; 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."; catch (boost::exception &e)
break; {
LOG(ERROR) << boost::diagnostic_information(e);
} }
} }