]> git.tdb.fi Git - libs/datafile.git/commitdiff
Report locations of errors through multiple levels of referenced files
authorMikko Rasa <tdb@tdb.fi>
Fri, 19 Feb 2021 23:10:34 +0000 (01:10 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 19 Feb 2021 23:10:34 +0000 (01:10 +0200)
source/except.cpp
source/except.h
source/loader.cpp

index d3929f6c7a8592fb6cf26fef9956c9e916f7965d..c698d83c697878945121ea666b06526998f5bd4c 100644 (file)
@@ -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)
index cc8c1fbdcd6b3a4f5b303023871d667b66287381..34d9e77810d838b694e0023a364271ecd1bb5afc 100644 (file)
@@ -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; }
index 960621cf3b47c48fcef8d5e016c5bb210b4f31eb..3484799a3e4891b12b622139b646e27a582690a1 100644 (file)
@@ -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)
        {