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>
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
{
23 error(const std::string
& what
) : std::logic_error(what
) {}
26 class BOOST_PROGRAM_OPTIONS_DECL invalid_syntax
: public error
{
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
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
{
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
{
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
{
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
74 class BOOST_PROGRAM_OPTIONS_DECL multiple_occurrences
: public error
{
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
{
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();
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
97 invalid_option_value(const std::string
& value
);
98 #ifndef BOOST_NO_STD_WSTRING
99 invalid_option_value(const std::wstring
& value
);
103 /** Class thrown when there are too many positional options. */
104 class BOOST_PROGRAM_OPTIONS_DECL too_many_positional_options_error
: public error
{
106 too_many_positional_options_error(const std::string
& what
)
110 /** Class thrown when there are too few positional options. */
111 class BOOST_PROGRAM_OPTIONS_DECL too_few_positional_options_error
: public error
{
113 too_few_positional_options_error(const std::string
& what
)
117 class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_syntax
: public invalid_syntax
{
120 long_not_allowed
= 30,
121 long_adjacent_not_allowed
,
122 short_adjacent_not_allowed
,
123 empty_adjacent_parameter
,
128 invalid_command_line_syntax(const std::string
& tokens
, kind_t kind
);
131 static std::string
error_message(kind_t kind
);
136 class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_style
: public error
{
138 invalid_command_line_style(const std::string
& msg
)