Skip to content

Commit

Permalink
Remove inner try catch block since outer block will handle the error
Browse files Browse the repository at this point in the history
Removed ambiguity in log message
  • Loading branch information
kenrowland committed Feb 10, 2025
1 parent 6eda781 commit 1acb166
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions system/jlib/jmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,21 @@ bool MetricsManager::addMetric(const std::shared_ptr<IMetric> &pMetric)
bool metaDataOk = true;
for (auto &metaDataIt: metaData)
{
try
if (std::regex_match(metaDataIt.value, metaDataValidator))
{
if (std::regex_match(metaDataIt.value, metaDataValidator))
{
name.append(".").append(metaDataIt.value);
}
else
{
metaDataOk = false;
name.append(".").append(metaDataIt.value);
}
else
{
metaDataOk = false;
#ifdef _DEBUG
// In debug throw an exception to notify the developer of the invalid metadata value
throw makeStringExceptionV(MSGAUD_operator, "addMetric - Attempted to add metric with invalid metadata '%s' for metric '%s'", metaDataIt.value.c_str(), name.c_str());
// In debug throw an exception to notify the developer of the invalid metadata value
throw makeStringExceptionV(MSGAUD_operator, "addMetric - Attempted to add metric with invalid metadata '%s' for metric '%s'", metaDataIt.value.c_str(), name.c_str());
#else
// In release notify the operator of the error, but don't prevent the system from loading
OERRLOG("addMetric - Metric metadata '%s' is not valid for metric '%s', metric not added", metaDataIt.value.c_str(), name.c_str());
break;
// In release notify the operator of the error, but don't prevent the system from loading
OERRLOG("addMetric - Metric metadata '%s' is not valid for metric '%s', metric not added", metaDataIt.value.c_str(), name.c_str());
break;
#endif
}
}
catch (std::regex_error &regex_error)
{
throw; // rethrow the exception to be caught by the outer catch block
}
}

Expand Down Expand Up @@ -238,7 +231,7 @@ bool MetricsManager::addMetric(const std::shared_ptr<IMetric> &pMetric)
{
#ifdef _DEBUG
// In debug throw an exception so the developer knows there is a regex error
throw makeStringExceptionV(MSGAUD_operator, "Metrics manager failed to validate metric name/metaData, regex match error, code=%d, what=%s",
throw makeStringExceptionV(MSGAUD_operator, "Metrics manager failed to validate metric name or metadata, regex match error, code=%d, what=%s",
regex_error.code(), regex_error.what());
#else
// In release notify the operator of the error, but don't prevent the system from loading
Expand Down

0 comments on commit 1acb166

Please sign in to comment.