Cleanup exceptions.
[command.git] / include / command.h
index 8ecb280e78aff6bb4080c40fd2ae086f65b44f12..0cbb3d6eba84d4a02c1391f316f710de189c1514 100644 (file)
@@ -3,8 +3,10 @@
 
 #include <string>
 #include <vector>
+#include <typeinfo>
 
 #include "parameter.h"
+#include "exception/missingRequiredParameter.h"
 
 namespace command {
     /**
@@ -28,7 +30,11 @@ namespace command {
             try {
                 matchArguments(argc, argv);
             }
-            catch(std::invalid_argument exception) {
+            catch(const std::invalid_argument & exception) {
+                releaseMemory();
+                throw;
+            }
+            catch(const std::logic_error & exception) {
                 releaseMemory();
                 throw;
             }
@@ -53,6 +59,11 @@ namespace command {
                     }
                 }
             }
+            for(Parameter *param : parameters) {
+                if (param->isRequired() && !param->isUsed()) {
+                    throw MissingRequiredParameter(param->describe() + " is required but it was not passed");
+                }
+            }
         }
 
         /**