fix doc example typo
[boost.git] / boost / program_options / errors.hpp
blob11ff01bd481ecdc0ed962247608e916d4685e96f
1 // Copyright Vladimir Prus 2002-2004.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt
4 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_ERRORS_VP_2003_01_02
8 #define BOOST_ERRORS_VP_2003_01_02
10 #include <boost/program_options/config.hpp>
12 #include <string>
13 #include <stdexcept>
14 #include <vector>
18 namespace boost { namespace program_options {
20 /** Base class for all errors in the library. */
21 class BOOST_PROGRAM_OPTIONS_DECL error : public std::logic_error {
22 public:
23 error(const std::string& what) : std::logic_error(what) {}
26 class BOOST_PROGRAM_OPTIONS_DECL invalid_syntax : public error {
27 public:
28 invalid_syntax(const std::string& tokens, const std::string& msg)
29 : error(std::string(msg).append(" in '").append(tokens).append("'")),
30 tokens(tokens), msg(msg)
33 // gcc says that throw specification on dtor is loosened
34 // without this line
35 ~invalid_syntax() throw() {}
37 // TODO: copy ctor might throw
38 std::string tokens, msg;
41 /** Class thrown when option name is not recognized. */
42 class BOOST_PROGRAM_OPTIONS_DECL unknown_option : public error {
43 public:
44 unknown_option(const std::string& name)
45 : error(std::string("unknown option ").append(name))
49 /** Class thrown when there's ambiguity amoung several possible options. */
50 class BOOST_PROGRAM_OPTIONS_DECL ambiguous_option : public error {
51 public:
52 ambiguous_option(const std::string& name,
53 const std::vector<std::string>& alternatives)
54 : error(std::string("ambiguous option ").append(name)),
55 alternatives(alternatives)
58 ~ambiguous_option() throw() {}
60 // TODO: copy ctor might throw
61 std::vector<std::string> alternatives;
64 /** Class thrown when there are several option values, but
65 user called a method which cannot return them all. */
66 class BOOST_PROGRAM_OPTIONS_DECL multiple_values : public error {
67 public:
68 multiple_values(const std::string& what) : error(what) {}
71 /** Class thrown when there are several occurrences of an
72 option, but user called a method which cannot return
73 them all. */
74 class BOOST_PROGRAM_OPTIONS_DECL multiple_occurrences : public error {
75 public:
76 multiple_occurrences(const std::string& what) : error(what) {}
79 /** Class thrown when value of option is incorrect. */
80 class BOOST_PROGRAM_OPTIONS_DECL validation_error : public error {
81 public:
82 validation_error(const std::string& what) : error(what) {}
83 ~validation_error() throw() {}
84 void set_option_name(const std::string& option);
86 const char* what() const throw();
87 private:
88 mutable std::string m_message; // For on-demand formatting in 'what'
89 std::string m_option_name; // The name of the option which
90 // caused the exception.
93 class BOOST_PROGRAM_OPTIONS_DECL invalid_option_value
94 : public validation_error
96 public:
97 invalid_option_value(const std::string& value);
98 #ifndef BOOST_NO_STD_WSTRING
99 invalid_option_value(const std::wstring& value);
100 #endif
103 /** Class thrown when there are too many positional options. */
104 class BOOST_PROGRAM_OPTIONS_DECL too_many_positional_options_error : public error {
105 public:
106 too_many_positional_options_error(const std::string& what)
107 : error(what) {}
110 /** Class thrown when there are too few positional options. */
111 class BOOST_PROGRAM_OPTIONS_DECL too_few_positional_options_error : public error {
112 public:
113 too_few_positional_options_error(const std::string& what)
114 : error(what) {}
117 class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_syntax : public invalid_syntax {
118 public:
119 enum kind_t {
120 long_not_allowed = 30,
121 long_adjacent_not_allowed,
122 short_adjacent_not_allowed,
123 empty_adjacent_parameter,
124 missing_parameter,
125 extra_parameter
128 invalid_command_line_syntax(const std::string& tokens, kind_t kind);
129 kind_t kind() const;
130 protected:
131 static std::string error_message(kind_t kind);
132 private:
133 kind_t m_kind;
136 class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_style : public error {
137 public:
138 invalid_command_line_style(const std::string& msg)
139 : error(msg)
146 #endif