tclap: ArgException.h Source File

tclap 1.2.5

ArgException.h
Go to the documentation of this file.
1 // -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
2
3 /******************************************************************************
4 *
5 * file: ArgException.h
6 *
7 * Copyright (c) 2003, Michael E. Smoot .
8 * Copyright (c) 2017 Google LLC
9 * All rights reserved.
10 *
11 * See the file COPYING in the top directory of this distribution for
12 * more information.
13 *
14 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *
22 *****************************************************************************/
23
24
25 #ifndef TCLAP_ARG_EXCEPTION_H
26 #define TCLAP_ARG_EXCEPTION_H
27
28 #include <string>
29 #include <exception>
30
31 namespace TCLAP {
32
37 class ArgException : public std::exception
38 {
39 public:
40
48 ArgException( const std::string& text = "undefined exception",
49 const std::string& id = "undefined",
50 const std::string& td = "Generic ArgException")
51 : std::exception(),
52 _errorText(text),
53 _argId( id ),
54 _typeDescription(td)
55 { }
56
60 virtual ~ArgException() throw() { }
61
65 std::string error() const { return ( _errorText ); }
66
70 std::string argId() const
71 {
72 if ( _argId == "undefined" )
73 return " ";
74 else
75 return ( "Argument: " + _argId );
76 }
77
81 const char* what() const throw()
82 {
83 static std::string ex;
84 ex = _argId + " -- " + _errorText;
85 return ex.c_str();
86 }
87
92 std::string typeDescription() const
93 {
94 return _typeDescription;
95 }
96
97
98 private:
99
103 std::string _errorText;
104
108 std::string _argId;
109
114 std::string _typeDescription;
115
116 };
117
122 class ArgParseException : public ArgException
123 {
124 public:
131 ArgParseException( const std::string& text = "undefined exception",
132 const std::string& id = "undefined" )
133 : ArgException( text,
134 id,
135 std::string( "Exception found while parsing " ) +
136 std::string( "the value the Arg has been passed." ))
137 { }
138 };
139
144 class CmdLineParseException : public ArgException
145 {
146 public:
153 CmdLineParseException( const std::string& text = "undefined exception",
154 const std::string& id = "undefined" )
155 : ArgException( text,
156 id,
157 std::string( "Exception found when the values ") +
158 std::string( "on the command line do not meet ") +
159 std::string( "the requirements of the defined ") +
160 std::string( "Args." ))
161 { }
162 };
163
168 class SpecificationException : public ArgException
169 {
170 public:
177 SpecificationException( const std::string& text = "undefined exception",
178 const std::string& id = "undefined" )
179 : ArgException( text,
180 id,
181 std::string("Exception found when an Arg object ")+
182 std::string("is improperly defined by the ") +
183 std::string("developer." ))
184 { }
185
186 };
187
200 class ExitException {
201 public:
202 ExitException(int estat) : _estat(estat) {}
203
204 int getExitStatus() const { return _estat; }
205
206 private:
207 int _estat;
208 };
209
210 } // namespace TCLAP
211
212 #endif
213
TCLAP::ArgException
A simple class that defines and argument exception.
Definition: ArgException.h:38
TCLAP::ArgException::~ArgException
virtual ~ArgException()
Destructor.
Definition: ArgException.h:60
TCLAP::ArgException::ArgException
ArgException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
Definition: ArgException.h:48
TCLAP::ArgException::what
const char * what() const
Returns the arg id and error text.
Definition: ArgException.h:81
TCLAP::ArgException::typeDescription
std::string typeDescription() const
Returns the type of the exception.
Definition: ArgException.h:92
TCLAP::ArgException::argId
std::string argId() const
Returns the argument id.
Definition: ArgException.h:70
TCLAP::ArgException::error
std::string error() const
Returns the error text.
Definition: ArgException.h:65
TCLAP::ArgParseException
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
Definition: ArgException.h:123
TCLAP::ArgParseException::ArgParseException
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:131
TCLAP::CmdLineParseException
Thrown from CmdLine when the arguments on the command line are not properly specified,...
Definition: ArgException.h:145
TCLAP::CmdLineParseException::CmdLineParseException
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:153
TCLAP::ExitException
Thrown when TCLAP thinks the program should exit.
Definition: ArgException.h:200
TCLAP::ExitException::ExitException
ExitException(int estat)
Definition: ArgException.h:202
TCLAP::ExitException::getExitStatus
int getExitStatus() const
Definition: ArgException.h:204
TCLAP::SpecificationException
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: ArgException.h:169
TCLAP::SpecificationException::SpecificationException
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:177
TCLAP
Definition: Arg.h:48