From: Mikko Rasa Date: Thu, 13 Dec 2007 15:02:57 +0000 (+0000) Subject: Make use of KeyError's key parameter X-Git-Tag: 1.0~11 X-Git-Url: http://git.tdb.fi/?p=libs%2Fdatafile.git;a=commitdiff_plain;h=a02c84384a101c0dec48b6aa2dee53bac4bbd034 Make use of KeyError's key parameter --- diff --git a/source/binaryparser.cpp b/source/binaryparser.cpp index c3d53d7..ba6414b 100644 --- a/source/binaryparser.cpp +++ b/source/binaryparser.cpp @@ -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; } diff --git a/source/collection.h b/source/collection.h index 5fcaab3..f293428 100644 --- a/source/collection.h +++ b/source/collection.h @@ -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::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 *item=dynamic_cast *>(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 *item=dynamic_cast *>(i->second); if(!item) - throw TypeError("Item '"+name+"' is not of correct type"); + throw TypeError("Type mismatch on item '"+name+"'"); return item->data; } diff --git a/source/loader.cpp b/source/loader.cpp index 0a9f68f..67668cd 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -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;