From 607a1328ff83fcccd620472ce14cb2e5a580aaea Mon Sep 17 00:00:00 2001 From: Grzegorz Krajewski Date: Tue, 17 Nov 2015 23:01:50 +0100 Subject: [PATCH] Throw a runtime_error exception for start/stop Throwing a runtime_error exception after Timer::Start or Timer::Stop has been called twice. --- src/mlpack/core/util/timers.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/mlpack/core/util/timers.cpp b/src/mlpack/core/util/timers.cpp index 0dbd7d55a7..4c649b24b4 100644 --- a/src/mlpack/core/util/timers.cpp +++ b/src/mlpack/core/util/timers.cpp @@ -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); }