From: Mikko Rasa Date: Fri, 19 Feb 2021 23:10:34 +0000 (+0200) Subject: Report locations of errors through multiple levels of referenced files X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ef12cc79fddd527e895169f62d7424b18d5937ca;p=libs%2Fdatafile.git Report locations of errors through multiple levels of referenced files --- diff --git a/source/except.cpp b/source/except.cpp index d3929f6..c698d83 100644 --- a/source/except.cpp +++ b/source/except.cpp @@ -19,6 +19,12 @@ data_error::data_error(const string &s, unsigned l, const exception &e): line(l) { } +data_error::data_error(const string &s, unsigned l, const data_error &e): + runtime_error(format("%s\n%s", e.what(), make_what(s, l, "Referenced here"))), + source(s), + line(l) +{ } + string data_error::make_what(const string &s, unsigned l, const string &w) { if(l) diff --git a/source/except.h b/source/except.h index cc8c1fb..34d9e77 100644 --- a/source/except.h +++ b/source/except.h @@ -17,6 +17,7 @@ private: public: data_error(const std::string &, unsigned, const std::string &); data_error(const std::string &, unsigned, const std::exception &); + data_error(const std::string &, unsigned, const data_error &); virtual ~data_error() throw() { } const std::string &get_source() const { return source; } diff --git a/source/loader.cpp b/source/loader.cpp index 960621c..3484799 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -131,9 +131,12 @@ void Loader::load_statement(const Statement &st) throw logic_error("substatements ignored"); } } - catch(const data_error &) + catch(const data_error &e) { - throw; + if(e.get_source()!=st.source) + throw data_error(st.source, st.line, e); + else + throw; } catch(const exception &e) {