Browse Source

[1857] make ModuleSpecError derive from isc::Exception

Jelte Jansen 13 years ago
parent
commit
373ef178d7
2 changed files with 15 additions and 18 deletions
  1. 11 10
      src/lib/config/module_spec.cc
  2. 4 8
      src/lib/config/module_spec.h

+ 11 - 10
src/lib/config/module_spec.cc

@@ -40,13 +40,14 @@ check_leaf_item(ConstElementPtr spec, const std::string& name,
         if (spec->get(name)->getType() == type) {
             return;
         } else {
-            throw ModuleSpecError(name + " not of type " + Element::typeToName(type));
+            isc_throw(ModuleSpecError,
+                      name + " not of type " + Element::typeToName(type));
         }
     } else if (mandatory) {
         // todo: want parent item name, and perhaps some info about location
         // in list? or just catch and throw new...
         // or make this part non-throwing and check return value...
-        throw ModuleSpecError(name + " missing in " + spec->str());
+        isc_throw(ModuleSpecError, name + " missing in " + spec->str());
     }
 }
 
@@ -80,7 +81,7 @@ check_config_item(ConstElementPtr spec) {
 void
 check_config_item_list(ConstElementPtr spec) {
     if (spec->getType() != Element::list) {
-        throw ModuleSpecError("config_data is not a list of elements");
+        isc_throw(ModuleSpecError, "config_data is not a list of elements");
     }
     BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
         check_config_item(item);
@@ -122,7 +123,7 @@ void check_statistics_item_list(ConstElementPtr spec);
 void
 check_statistics_item_list(ConstElementPtr spec) {
     if (spec->getType() != Element::list) {
-        throw ModuleSpecError("statistics is not a list of elements");
+        isc_throw(ModuleSpecError, "statistics is not a list of elements");
     }
     BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
         check_config_item(item);
@@ -135,7 +136,7 @@ check_statistics_item_list(ConstElementPtr spec) {
             && item->contains("item_default")) {
             if(!check_format(item->get("item_default"),
                              item->get("item_format"))) {
-                throw ModuleSpecError(
+                isc_throw(ModuleSpecError, 
                     "item_default not valid type of item_format");
             }
         }
@@ -152,7 +153,7 @@ check_command(ConstElementPtr spec) {
 void
 check_command_list(ConstElementPtr spec) {
     if (spec->getType() != Element::list) {
-        throw ModuleSpecError("commands is not a list of elements");
+        isc_throw(ModuleSpecError, "commands is not a list of elements");
     }
     BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
         check_command(item);
@@ -183,7 +184,7 @@ check_module_specification(ConstElementPtr def) {
     try {
         check_data_specification(def);
     } catch (const TypeError& te) {
-        throw ModuleSpecError(te.what());
+        isc_throw(ModuleSpecError, te.what());
     }
 }
 }
@@ -314,14 +315,14 @@ moduleSpecFromFile(const std::string& file_name, const bool check)
     if (!file) {
         std::stringstream errs;
         errs << "Error opening " << file_name << ": " << strerror(errno);
-        throw ModuleSpecError(errs.str());
+        isc_throw(ModuleSpecError, errs.str());
     }
 
     ConstElementPtr module_spec_element = Element::fromJSON(file, file_name);
     if (module_spec_element->contains("module_spec")) {
         return (ModuleSpec(module_spec_element->get("module_spec"), check));
     } else {
-        throw ModuleSpecError("No module_spec in specification");
+        isc_throw(ModuleSpecError, "No module_spec in specification");
     }
 }
 
@@ -333,7 +334,7 @@ moduleSpecFromFile(std::ifstream& in, const bool check)
     if (module_spec_element->contains("module_spec")) {
         return (ModuleSpec(module_spec_element->get("module_spec"), check));
     } else {
-        throw ModuleSpecError("No module_spec in specification");
+        isc_throw(ModuleSpecError, "No module_spec in specification");
     }
 }
 

+ 4 - 8
src/lib/config/module_spec.h

@@ -26,15 +26,11 @@ namespace isc { namespace config {
     /// A standard ModuleSpec exception that is thrown when a
     /// specification is not in the correct form.
     ///
-    /// TODO: use jinmei's exception class as a base and not c_str in
-    /// what() there
-    class ModuleSpecError : public std::exception {
+    class ModuleSpecError : public isc::Exception {
     public:
-        ModuleSpecError(std::string m = "Module specification is invalid") : msg(m) {}
-        ~ModuleSpecError() throw() {}
-        const char* what() const throw() { return (msg.c_str()); }
-    private:
-        std::string msg;
+        ModuleSpecError(const char* file, size_t line,
+                        const char* what = "Module specification is invalid") :
+            isc::Exception(file, line, what) {}
     };
 
     ///