tclap 1.4.0
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#ifndef TCLAP_ARG_EXCEPTION_H
25#define TCLAP_ARG_EXCEPTION_H
26
27#include <exception>
28#include <string>
29
30namespace TCLAP {
31
36class ArgException : public std::exception {
37public:
45 ArgException(const std::string &text = "undefined exception",
46 const std::string &id = "undefined",
47 const std::string &td = "Generic ArgException")
48 : std::exception(),
49 _errorText(text),
50 _argId(id),
51 _typeDescription(td),
52 _what(_argId + " -- " + _errorText) {}
53
57 virtual ~ArgException() throw() {}
58
62 std::string error() const { return (_errorText); }
63
67 std::string argId() const {
68 if (_argId == "undefined")
69 return " ";
70 else
71 return ("Argument: " + _argId);
72 }
73
77 const char *what() const throw() {
78 return _what.c_str();
79 }
80
85 std::string typeDescription() const { return _typeDescription; }
86
87private:
91 std::string _errorText;
92
96 std::string _argId;
97
102 std::string _typeDescription;
103
104 // Prepared in the constructor: what() cannot allocate or throw.
105 std::string _what;
106};
107
113public:
120 ArgParseException(const std::string &text = "undefined exception",
121 const std::string &id = "undefined")
122 : ArgException(text, id,
123 std::string("Exception found while parsing ") +
124 std::string("the value the Arg has been passed.")) {}
125};
126
132public:
139 CmdLineParseException(const std::string &text = "undefined exception",
140 const std::string &id = "undefined")
141 : ArgException(text, id,
142 std::string("Exception found when the values ") +
143 std::string("on the command line do not meet ") +
144 std::string("the requirements of the defined ") +
145 std::string("Args.")) {}
146};
147
153public:
160 SpecificationException(const std::string &text = "undefined exception",
161 const std::string &id = "undefined")
162 : ArgException(text, id,
163 std::string("Exception found when an Arg object ") +
164 std::string("is improperly defined by the ") +
165 std::string("developer.")) {}
166};
167
181public:
182 explicit ExitException(int estat) : _estat(estat) {}
183
184 int getExitStatus() const { return _estat; }
185
186private:
187 int _estat;
188};
189
190} // namespace TCLAP
191
192#endif // TCLAP_ARG_EXCEPTION_H
A simple class that defines and argument exception.
virtual ~ArgException()
Destructor.
ArgException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
std::string typeDescription() const
Returns the type of the exception.
std::string argId() const
Returns the argument id.
std::string error() const
Returns the error text.
const char * what() const
Returns the arg id and error text.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Thrown from CmdLine when the arguments on the command line are not properly specified,...
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Thrown when TCLAP thinks the program should exit.
int getExitStatus() const
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition Arg.h:52