From ef12cc79fddd527e895169f62d7424b18d5937ca Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 20 Feb 2021 01:10:34 +0200 Subject: [PATCH] Report locations of errors through multiple levels of referenced files --- source/except.cpp | 6 ++++++ source/except.h | 1 + source/loader.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-) 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) { -- 2.43.0