]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/binaryparser.cpp
Exception rework for parser components
[libs/datafile.git] / source / binaryparser.cpp
index d2fca32ef3a2155eb78eec3034e67649336c3c0f..550319f46d0a7af21bd939b477adaac1047101c8 100644 (file)
@@ -9,6 +9,17 @@ using namespace std;
 namespace Msp {
 namespace DataFile {
 
+class bad_definition: public runtime_error
+{
+public:
+       bad_definition(const std::string &w):
+               runtime_error(w)
+       { }
+
+       virtual ~bad_definition() throw() { }
+};
+
+
 BinaryParser::BinaryParser(Input &i, const string &s):
        ParserMode(i, s),
        first(true)
@@ -25,7 +36,7 @@ Statement BinaryParser::parse()
                if(st.keyword=="__kwd")
                {
                        if(st.args.size()!=3)
-                               throw_at(TypeError("Keyword definition must have three arguments"), src);
+                               throw bad_definition("__kwd");
 
                        const unsigned id = st.args[0].get<unsigned>();
                        const string &kw = st.args[1].get<const string &>();
@@ -35,7 +46,7 @@ Statement BinaryParser::parse()
                else if(st.keyword=="__str")
                {
                        if(st.args.size()!=2)
-                               throw_at(TypeError("String definition must have two arguments"), src);
+                               throw bad_definition("__str");
 
                        const unsigned id = st.args[0].get<unsigned>();
                        strings[id] = st.args[1].get<const string &>();