From a02c84384a101c0dec48b6aa2dee53bac4bbd034 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 13 Dec 2007 15:02:57 +0000 Subject: [PATCH] Make use of KeyError's key parameter --- source/binaryparser.cpp | 2 +- source/collection.h | 10 +++++----- source/loader.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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; -- 2.45.2