From 943504fd983557f1187d5e547f65e9a1a0e23d99 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 12 Jan 2025 17:48:20 -0500 Subject: [PATCH] move timespec2seconds exception handling to calling function --- src/timer.cpp | 12 +++++++++--- src/utils.cpp | 10 +++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/timer.cpp b/src/timer.cpp index c6f6401799..667c0e8946 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -15,6 +15,7 @@ #include "comm.h" #include "error.h" +#include "tokenizer.h" #include "fmt/chrono.h" #include @@ -231,9 +232,14 @@ void Timer::modify_params(int narg, char **arg) } else if (strcmp(arg[iarg], "timeout") == 0) { ++iarg; if (iarg < narg) { - _timeout = utils::timespec2seconds(arg[iarg]); - } else - error->all(FLERR, "Illegal timer command"); + try { + _timeout = utils::timespec2seconds(arg[iarg]); + } catch (TokenizerException &) { + error->all(FLERR, "Illegal timeout time: {}", arg[iarg]); + } + } else { + utils::missing_cmd_args(FLERR, "timer timeout", error); + } } else if (strcmp(arg[iarg], "every") == 0) { ++iarg; if (iarg < narg) { diff --git a/src/utils.cpp b/src/utils.cpp index 59984c8443..0f5b50baf2 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1744,13 +1744,9 @@ double utils::timespec2seconds(const std::string ×pec) ValueTokenizer values(timespec, ":"); - try { - for (i = 0; i < 3; i++) { - if (!values.has_next()) break; - vals[i] = values.next_double(); - } - } catch (TokenizerException &) { - return -1.0; + for (i = 0; i < 3; i++) { + if (!values.has_next()) break; + vals[i] = values.next_double(); } if (i == 3)