Skip to content

Commit

Permalink
Merge pull request #2233 from jamescowens/fix_catch_exception_by_valu…
Browse files Browse the repository at this point in the history
…e_warning_MilliTimer

util: Tweak exception handling in MilliTimer class to eliminate compiler warnings
  • Loading branch information
jamescowens authored Jul 15, 2021
2 parents fd2de61 + a1fed42 commit 3014f62
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/util/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ int64_t MilliTimer::GetStartTime(const std::string& label)

try
{

LOCK(cs_timer_map_lock);

// This will throw an internal exception if the entry specified by label doesn't exist.
internal_timer = timer_map.at(label);
}
catch (std::out_of_range) {}
catch (std::out_of_range&) {
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.");
}

return internal_timer.start_time;
}
Expand All @@ -156,9 +157,9 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons
//Because of the exception guard above the map entry can be updated with [].
timer_map[label] = internal_timer;
}
catch (std::out_of_range)
catch (std::out_of_range&)
{
//Re-initialize timer if internal exception is thrown.
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.");
timer = {};
return timer;
}
Expand Down

0 comments on commit 3014f62

Please sign in to comment.