Add try-catch block in example in order to fix memory leaks. Added specialized except...
[command.git] / include / exception / optionFailedConversion.h
1 #ifndef __COMMAND_EXCEPTION_OPTION_FAILED_CONVERSION_H
2 #define __COMMAND_EXCEPTION_OPTION_FAILED_CONVERSION_H
3
4 #include <stdexcept>
5 #include <string>
6
7 namespace command {
8
9 /**
10  * Helper template class used for releasing resources.
11  */
12 class OptionFailedConversion : public std::invalid_argument {
13 protected:
14     std::string message;
15 public:
16     explicit OptionFailedConversion(const std::string& what_arg) :
17         std::invalid_argument(what_arg), message(what_arg) { }
18
19     explicit OptionFailedConversion(const char* what_arg) :
20         std::invalid_argument(what_arg), message(what_arg) { }
21
22     virtual const char* what() const throw() {
23         return message.c_str();
24     }
25 };
26
27 }
28
29 #endif /* __COMMAND_EXCEPTION_OPTION_FAILED_CONVERSION_H */