]> git.tdb.fi Git - libs/datafile.git/commitdiff
Make use of KeyError's key parameter
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Dec 2007 15:02:57 +0000 (15:02 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Dec 2007 15:02:57 +0000 (15:02 +0000)
source/binaryparser.cpp
source/collection.h
source/loader.cpp

index c3d53d7241d4aaa069aeee617f98b16f6a504cb8..ba6414bc77a369a7eb2d7c51e06e412aee16fb0a 100644 (file)
@@ -162,7 +162,7 @@ string BinaryParser::parse_enum()
        unsigned id=parse_int();
        EnumMap::iterator i=enums.find(id);
        if(i==enums.end())
-               throw KeyError("Unknown enum");
+               throw KeyError("Unknown enum", lexical_cast(id));
        return i->second;
 }
 
index 5fcaab34f35345406de07e372a70cb972efc2a67..f293428c8cdd0fc046019531335ccf6d28b525fc 100644 (file)
@@ -192,7 +192,7 @@ public:
        void add(const std::string &name, T *d)
        {
                if(items.count(name))
-                       throw KeyError("Duplicate key '"+name+"' in collection");
+                       throw KeyError("Duplicate key in collection", name);
 
                items[name]=new Item<typename RemoveConst<T>::Type>(d);
        }
@@ -207,11 +207,11 @@ public:
 
                ItemMap::const_iterator i=items.find(name);
                if(i==items.end())
-                       throw KeyError("Item '"+name+"' not found in collection");
+                       throw KeyError("Item not found in collection", name);
 
                const Item<NCT> *item=dynamic_cast<const Item<NCT> *>(i->second);
                if(!item)
-                       throw TypeError("Item '"+name+"' is not of correct type");
+                       throw TypeError("Type mismatch on item '"+name+"'");
 
                return item->data;
        }
@@ -239,12 +239,12 @@ public:
                                        return d;
                                }
                        }
-                       throw KeyError("Item '"+name+"' not found in collection");
+                       throw KeyError("Item not found in collection", name);
                }
 
                const Item<NCT> *item=dynamic_cast<const Item<NCT> *>(i->second);
                if(!item)
-                       throw TypeError("Item '"+name+"' is not of correct type");
+                       throw TypeError("Type mismatch on item '"+name+"'");
 
                return item->data;
        }
index 0a9f68f249a8d56fe76ab5ba36f5c5bfe76a57e8..67668cdea1f5bc52b76c7c02c401fda501d9531e 100644 (file)
@@ -51,7 +51,7 @@ void Loader::load_statement(const Statement &st)
        cur_st=&st;
        ActionMap::iterator j=actions.find(st.keyword);
        if(j==actions.end())
-               throw KeyError(st.get_location()+": Unknown keyword '"+st.keyword+"'");
+               throw KeyError(st.get_location()+": Unknown keyword", st.keyword);
        if(j->second)
                j->second->execute(*this, st);
        cur_st=0;