2
/******************************************************************************
6
* Copyright (c) 2003, Michael E. Smoot .
9
* See the file COPYING in the top directory of this distribution for
12
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
* DEALINGS IN THE SOFTWARE.
20
*****************************************************************************/
23
#ifndef TCLAP_ARG_EXCEPTION_H
24
#define TCLAP_ARG_EXCEPTION_H
32
* A simple class that defines and argument exception. Should be caught
33
* whenever a CmdLine is created and parsed.
35
class ArgException : public std::exception
41
* \param text - The text of the exception.
42
* \param id - The text identifying the argument source.
43
* \param td - Text describing the type of ArgException it is.
46
ArgException( const std::string& text = "undefined exception",
47
const std::string& id = "undefined",
48
const std::string& td = "Generic ArgException")
58
virtual ~ArgException() throw() { }
61
* Returns the error text.
63
std::string error() const { return ( _errorText ); }
66
* Returns the argument id.
68
std::string argId() const
70
if ( _argId == "undefined" )
73
return ( "Argument: " + _argId );
77
* Returns the arg id and error text.
79
const char* what() const throw()
81
static std::string ex;
82
ex = _argId + " -- " + _errorText;
87
* Returns the type of the exception. Used to explain and distinguish
88
* between different child exceptions.
90
std::string typeDescription() const
92
return _typeDescription;
99
* The text of the exception message.
101
std::string _errorText;
104
* The argument related to this exception.
109
* Describes the type of the exception. Used to distinguish
110
* between different child exceptions.
112
std::string _typeDescription;
117
* Thrown from within the child Arg classes when it fails to properly
118
* parse the argument it has been passed.
120
class ArgParseException : public ArgException
125
* \param text - The text of the exception.
126
* \param id - The text identifying the argument source
129
ArgParseException( const std::string& text = "undefined exception",
130
const std::string& id = "undefined" )
131
: ArgException( text,
133
std::string( "Exception found while parsing " ) +
134
std::string( "the value the Arg has been passed." ))
139
* Thrown from CmdLine when the arguments on the command line are not
140
* properly specified, e.g. too many arguments, required argument missing, etc.
142
class CmdLineParseException : public ArgException
147
* \param text - The text of the exception.
148
* \param id - The text identifying the argument source
151
CmdLineParseException( const std::string& text = "undefined exception",
152
const std::string& id = "undefined" )
153
: ArgException( text,
155
std::string( "Exception found when the values ") +
156
std::string( "on the command line do not meet ") +
157
std::string( "the requirements of the defined ") +
158
std::string( "Args." ))
163
* Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
164
* same flag as another Arg, same name, etc.
166
class SpecificationException : public ArgException
171
* \param text - The text of the exception.
172
* \param id - The text identifying the argument source
175
SpecificationException( const std::string& text = "undefined exception",
176
const std::string& id = "undefined" )
177
: ArgException( text,
179
std::string("Exception found when an Arg object ")+
180
std::string("is improperly defined by the ") +
181
std::string("developer." ))