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 ////////////////