diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-05-17 14:09:42 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-05-17 14:09:42 +0200 |
| commit | c3d53d588dedb007b26809d85187027d1eba8183 (patch) | |
| tree | 64f65cb1538b6ed43f246cb52961e336a01f202d /src/string.cc | |
| parent | 37a23633019b070b69e4e5e5b6804a5d94722342 (diff) | |
revive str_to_int so that the good exception type is thrown on error
Diffstat (limited to 'src/string.cc')
| -rw-r--r-- | src/string.cc | 12 |
1 files changed, 12 insertions, 0 deletions
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<String> 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()}; |
