From c3d53d588dedb007b26809d85187027d1eba8183 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 17 May 2013 14:09:42 +0200 Subject: revive str_to_int so that the good exception type is thrown on error --- src/string.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/string.cc') diff --git a/src/string.cc b/src/string.cc index e7dd167f..2c180e50 100644 --- a/src/string.cc +++ b/src/string.cc @@ -23,6 +23,18 @@ std::vector split(const String& str, char separator) return res; } +int str_to_int(const String& str) +{ + try + { + return stoi(str); + } + catch (std::logic_error&) + { + throw runtime_error(str + "is not a number"); + } +} + String option_to_string(const Regex& re) { return String{re.str()}; -- cgit v1.2.3