From a378998e34ff15187e8626f5159aa8fea61a9c03 Mon Sep 17 00:00:00 2001 From: ado Date: Sun, 6 Aug 2023 14:04:21 +0200 Subject: [PATCH] Update parser exception handling for invalid split/conversion --- include/ss/parser.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 978d4b4..19ca4cd 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -98,9 +98,9 @@ public: if constexpr (throw_on_error) { try { reader_.parse(); - } catch (...) { + } catch (const ss::exception& e) { read_line(); - throw; + decorate_rethrow(e); } } else { reader_.parse(); @@ -126,9 +126,9 @@ public: auto value = reader_.converter_.template convert(); read_line(); return value; - } catch (...) { + } catch (const ss::exception& e) { read_line(); - throw; + decorate_rethrow(e); } } @@ -597,6 +597,16 @@ private: } } + void decorate_rethrow(const ss::exception& e) const { + static_assert(throw_on_error, + "throw_on_error needs to be enabled to use this method"); + throw ss::exception{std::string{file_name_} + .append(" ") + .append(std::to_string(reader_.line_number_)) + .append(": ") + .append(e.what())}; + } + //////////////// // line reading ////////////////