]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/collection.h
Make use of KeyError's key parameter
[libs/datafile.git] / source / collection.h
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;
        }