]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/binaryparser.cpp
Refactor exceptions
[libs/datafile.git] / source / binaryparser.cpp
index 214c35e70d3793437e786f90d0f99fd60a1fbd66..40736896c01bf13aaa789b2033050cbda5b338fc 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspdatafile
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -31,7 +31,7 @@ Statement BinaryParser::parse()
                if(st.keyword=="__kwd")
                {
                        if(st.args.size()!=3)
-                               throw TypeError(src+": Keyword definition must have three arguments");
+                               throw_at(TypeError("Keyword definition must have three arguments"), src);
 
                        const unsigned id=st.args[0].get<unsigned>();
                        const string &kw=st.args[1].get<const string &>();
@@ -41,7 +41,7 @@ Statement BinaryParser::parse()
                else if(st.keyword=="__str")
                {
                        if(st.args.size()!=2)
-                               throw TypeError(src+": String definition must have two arguments");
+                               throw_at(TypeError("String definition must have two arguments"), src);
 
                        const unsigned id=st.args[0].get<unsigned>();
                        strings[id]=st.args[1].get<const string &>();
@@ -63,7 +63,7 @@ Statement BinaryParser::parse_statement()
 
        Dictionary::const_iterator i=dict.find(id);
        if(i==dict.end())
-               throw ParseError(format("%s: Unknown statement ID %d", src, id), src, 0);
+               throw_at(KeyError("Unknown statement ID", lexical_cast(id)), src);
        const DictEntry &de=i->second;
 
        Statement result;
@@ -171,7 +171,7 @@ const string &BinaryParser::lookup_string(unsigned id) const
 {
        StringMap::const_iterator i=strings.find(id);
        if(i==strings.end())
-               throw KeyError("Unknown string", lexical_cast(id));
+               throw_at(KeyError("Unknown string", lexical_cast(id)), src);
        return i->second;
 }