Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PROGRAM_OPTIONS_ERRORS_H_INCLUDED
00023 #define PROGRAM_OPTIONS_ERRORS_H_INCLUDED
00024 #include <stdexcept>
00025 #include <string>
00026 namespace ProgramOptions {
00027
00029 class Error : public std::logic_error {
00030 public:
00031 explicit Error(const std::string& what) : std::logic_error(what) {}
00032 };
00033
00035 class SyntaxError : public Error {
00036 public:
00037 enum Type {
00038 missing_value,
00039 extra_value,
00040 invalid_format
00041 };
00042 SyntaxError(Type t, const std::string& key);
00043 ~SyntaxError() throw () {}
00044 Type type() const { return type_; }
00045 const std::string& key() const { return key_; }
00046 private:
00047 std::string key_;
00048 Type type_;
00049 };
00050
00052 class ContextError : public Error {
00053 public:
00054 enum Type {
00055 duplicate_option,
00056 unknown_option,
00057 ambiguous_option,
00058 unknown_group,
00059 };
00060 ContextError(const std::string& ctx, Type t, const std::string& key, const std::string& desc = "");
00061 ~ContextError() throw () {}
00062 Type type() const { return type_; }
00063 const std::string& key() const { return key_; }
00064 const std::string& ctx() const { return ctx_; }
00065 private:
00066 std::string ctx_;
00067 std::string key_;
00068 Type type_;
00069 };
00070
00071 class DuplicateOption : public ContextError {
00072 public:
00073 DuplicateOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::duplicate_option, key) {}
00074 ~DuplicateOption() throw () {}
00075 };
00076 class UnknownOption : public ContextError {
00077 public:
00078 UnknownOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::unknown_option, key) {}
00079 ~UnknownOption() throw () {}
00080 };
00081 class AmbiguousOption : public ContextError {
00082 public:
00083 AmbiguousOption(const std::string& ctx, const std::string& key, const std::string& alt) : ContextError(ctx, ContextError::ambiguous_option, key, alt) {}
00084 ~AmbiguousOption() throw () {}
00085 };
00086
00088 class ValueError : public Error {
00089 public:
00090 enum Type {
00091 multiple_occurences,
00092 invalid_default,
00093 invalid_value
00094 };
00095 ValueError(const std::string& ctx, Type t, const std::string& opt, const std::string& value);
00096 ~ValueError() throw () {}
00097 Type type() const { return type_; }
00098 const std::string& key() const { return key_; }
00099 const std::string& ctx() const { return ctx_; }
00100 const std::string& value()const { return value_;}
00101 private:
00102 std::string ctx_;
00103 std::string key_;
00104 std::string value_;
00105 Type type_;
00106 };
00107
00108
00109 }
00110 #endif