Main MRPT website > C++ reference for MRPT 1.4.0
ArgException.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9
10/******************************************************************************
11 *
12 * file: ArgException.h
13 *
14 * Copyright (c) 2003, Michael E. Smoot .
15 * All rights reverved.
16 *
17 * See the file COPYING in the top directory of this distribution for
18 * more information.
19 *
20 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 *****************************************************************************/
29
30
31#ifndef TCLAP_ARG_EXCEPTION_H
32#define TCLAP_ARG_EXCEPTION_H
33
34#include <string>
35#include <exception>
36#include <stdexcept>
37
38namespace TCLAP {
39
40/**
41 * A simple class that defines and argument exception. Should be caught
42 * whenever a CmdLine is created and parsed.
43 */
44class ArgException : public std::exception
45{
46 public:
47
48 /**
49 * Constructor.
50 * \param text - The text of the exception.
51 * \param id - The text identifying the argument source.
52 * \param td - Text describing the type of ArgException it is.
53 * of the exception.
54 */
55 ArgException( const std::string& text = "undefined exception",
56 const std::string& id = "undefined",
57 const std::string& td = "Generic ArgException")
58 : std::exception(),
59 _errorText(text),
60 _argId( id ),
62 { }
63
64 /**
65 * Destructor.
66 */
67 virtual ~ArgException() throw() { }
68
69 /**
70 * Returns the error text.
71 */
72 std::string error() const { return ( _errorText ); }
73
74 /**
75 * Returns the argument id.
76 */
77 std::string argId() const
78 {
79 if ( _argId == "undefined" )
80 return " ";
81 else
82 return ( "Argument: " + _argId );
83 }
84
85 /**
86 * Returns the arg id and error text.
87 */
88 const char* what() const throw()
89 {
90 static std::string ex;
91 ex = _argId + " -- " + _errorText;
92 return ex.c_str();
93 }
94
95 /**
96 * Returns the type of the exception. Used to explain and distinguish
97 * between different child exceptions.
98 */
99 std::string typeDescription() const
100 {
101 return _typeDescription;
102 }
103
104
105 private:
106
107 /**
108 * The text of the exception message.
109 */
110 std::string _errorText;
111
112 /**
113 * The argument related to this exception.
114 */
115 std::string _argId;
116
117 /**
118 * Describes the type of the exception. Used to distinguish
119 * between different child exceptions.
120 */
121 std::string _typeDescription;
122
123};
124
125/**
126 * Thrown from within the child Arg classes when it fails to properly
127 * parse the argument it has been passed.
128 */
130{
131 public:
132 /**
133 * Constructor.
134 * \param text - The text of the exception.
135 * \param id - The text identifying the argument source
136 * of the exception.
137 */
138 ArgParseException( const std::string& text = "undefined exception",
139 const std::string& id = "undefined" )
140 : ArgException( text,
141 id,
142 std::string( "Exception found while parsing " ) +
143 std::string( "the value the Arg has been passed." ))
144 { }
145};
146
147/**
148 * Thrown from CmdLine when the arguments on the command line are not
149 * properly specified, e.g. too many arguments, required argument missing, etc.
150 */
152{
153 public:
154 /**
155 * Constructor.
156 * \param text - The text of the exception.
157 * \param id - The text identifying the argument source
158 * of the exception.
159 */
160 CmdLineParseException( const std::string& text = "undefined exception",
161 const std::string& id = "undefined" )
162 : ArgException( text,
163 id,
164 std::string( "Exception found when the values ") +
165 std::string( "on the command line do not meet ") +
166 std::string( "the requirements of the defined ") +
167 std::string( "Args." ))
168 { }
169};
170
171/**
172 * Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
173 * same flag as another Arg, same name, etc.
174 */
176{
177 public:
178 /**
179 * Constructor.
180 * \param text - The text of the exception.
181 * \param id - The text identifying the argument source
182 * of the exception.
183 */
184 SpecificationException( const std::string& text = "undefined exception",
185 const std::string& id = "undefined" )
186 : ArgException( text,
187 id,
188 std::string("Exception found when an Arg object ")+
189 std::string("is improperly defined by the ") +
190 std::string("developer." ))
191 { }
192
193};
194
195/**
196 * (Added by JLBC for MRPT): An exception that indicates to CmdLine::parse that
197 * help,version,... have been invoked so it should return false for the main program to exit.
198 */
199class ActionDoneException : public std::runtime_error
200{
201public:
202 ActionDoneException(const std::string &text = std::string() ) :
203 std::runtime_error(text.c_str())
204 {
205 }
206};
207
208
209} // namespace TCLAP
210
211#endif
212
(Added by JLBC for MRPT): An exception that indicates to CmdLine::parse that help,...
Definition: ArgException.h:200
ActionDoneException(const std::string &text=std::string())
Definition: ArgException.h:202
A simple class that defines and argument exception.
Definition: ArgException.h:45
virtual ~ArgException()
Destructor.
Definition: ArgException.h:67
ArgException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
Definition: ArgException.h:55
std::string _argId
The argument related to this exception.
Definition: ArgException.h:115
std::string _typeDescription
Describes the type of the exception.
Definition: ArgException.h:121
std::string typeDescription() const
Returns the type of the exception.
Definition: ArgException.h:99
std::string argId() const
Returns the argument id.
Definition: ArgException.h:77
std::string _errorText
The text of the exception message.
Definition: ArgException.h:110
std::string error() const
Returns the error text.
Definition: ArgException.h:72
const char * what() const
Returns the arg id and error text.
Definition: ArgException.h:88
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
Definition: ArgException.h:130
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:138
Thrown from CmdLine when the arguments on the command line are not properly specified,...
Definition: ArgException.h:152
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:160
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: ArgException.h:176
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:184
Definition: Arg.h:44
STL namespace.



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Tue Jan 17 22:27:43 UTC 2023