Throw a runtime_error exception for start/stop

Throwing a runtime_error exception after Timer::Start or Timer::Stop has been called twice.
This commit is contained in:
Grzegorz Krajewski
2015-11-17 23:01:50 +01:00
parent 7d4d0a7138
commit 607a1328ff
+22
View File
@@ -33,6 +33,17 @@ inline void timersub(const timeval* tvp, const timeval* uvp, timeval* vvp)
*/
void Timer::Start(const std::string& name)
{
if((timerState[name] == 1) && (name != "total_time"))
{
std::ostringstream error;
error << "Timer::Start(): timer '" << name
<< "' has already been " << "started";
throw std::runtime_error(error.str());
}
timerState[name] = true;
CLI::GetSingleton().timer.StartTimer(name);
}
@@ -41,6 +52,17 @@ void Timer::Start(const std::string& name)
*/
void Timer::Stop(const std::string& name)
{
if((timerState[name] == 0) && (name != "total_time"))
{
std::ostringstream error;
error << "Timer::Stop(): timer '" << name
<< "' has already been " << "stopped";
throw std::runtime_error(error.str());
}
timerState[name] = false;
CLI::GetSingleton().timer.StopTimer(name);
}