Add try-catch block in example in order to fix memory leaks. Added specialized except...
[command.git] / src / main.cpp
index 5cf4e83d018373e5e665bafaee685ee2989e7bff..42c44cb57118ee8b6e0bd2096c31fd4e9de5658d 100644 (file)
@@ -21,12 +21,18 @@ void void_function(void) {
 }
 
 int main(int argc, char *argv[]) {
-    Command command(argc, argv, {
-//         new Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
-        new Required(new Argument<bool>("File path", argument_function)),
-        new Option<std::string>("f", "Optional file", option_function),
-        new Option<void>("h", "Help", void_function)
-    });
+    try {
+        Command command(argc, argv, {
+//             new Argument<std::string>("File path", [](std::string value)->void { std::cout << "Hello from lambda " << value << std::endl; }),
+            new Required(new Argument<bool>("File path", argument_function)),
+            new Option<std::string>("f", "Optional file", option_function),
+            new Option<void>("h", "Help", void_function)
+        });
+
+    }
+    catch(const std::exception & e) {
+        std::cout << e.what() << std::endl;
+    }
 
     return 0;
 }
\ No newline at end of file