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 
30 namespace TCLAP {
31 
36 class ArgException : public std::exception {
37 public:
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 
56  virtual ~ArgException() throw() {}
57 
61  std::string error() const { return (_errorText); }
62 
66  std::string argId() const {
67  if (_argId == "undefined")
68  return " ";
69  else
70  return ("Argument: " + _argId);
71  }
72 
76  const char *what() const throw() {
77  static std::string ex;
78  ex = _argId + " -- " + _errorText;
79  return ex.c_str();
80  }
81 
86  std::string typeDescription() const { return _typeDescription; }
87 
88 private:
92  std::string _errorText;
93 
97  std::string _argId;
98 
103  std::string _typeDescription;
104 };
105 
111 public:
118  ArgParseException(const std::string &text = "undefined exception",
119  const std::string &id = "undefined")
120  : ArgException(text, id,
121  std::string("Exception found while parsing ") +
122  std::string("the value the Arg has been passed.")) {}
123 };
124 
130 public:
137  CmdLineParseException(const std::string &text = "undefined exception",
138  const std::string &id = "undefined")
139  : ArgException(text, id,
140  std::string("Exception found when the values ") +
141  std::string("on the command line do not meet ") +
142  std::string("the requirements of the defined ") +
143  std::string("Args.")) {}
144 };
145 
151 public:
158  SpecificationException(const std::string &text = "undefined exception",
159  const std::string &id = "undefined")
160  : ArgException(text, id,
161  std::string("Exception found when an Arg object ") +
162  std::string("is improperly defined by the ") +
163  std::string("developer.")) {}
164 };
165 
179 public:
180  explicit ExitException(int estat) : _estat(estat) {}
181 
182  int getExitStatus() const { return _estat; }
183 
184 private:
185  int _estat;
186 };
187 
188 } // namespace TCLAP
189 
190 #endif // TCLAP_ARG_EXCEPTION_H
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:158
A simple class that defines and argument exception.
Definition: ArgException.h:36
Thrown from CmdLine when the arguments on the command line are not properly specified, e.g.
Definition: ArgException.h:129
virtual ~ArgException()
Destructor.
Definition: ArgException.h:56
std::string argId() const
Returns the argument id.
Definition: ArgException.h:66
ArgException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
Definition: ArgException.h:45
ExitException(int estat)
Definition: ArgException.h:180
Thrown when TCLAP thinks the program should exit.
Definition: ArgException.h:178
std::string typeDescription() const
Returns the type of the exception.
Definition: ArgException.h:86
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: ArgException.h:150
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:118
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:137
int getExitStatus() const
Definition: ArgException.h:182
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
Definition: ArgException.h:110
Definition: Arg.h:46
std::string error() const
Returns the error text.
Definition: ArgException.h:61
const char * what() const
Returns the arg id and error text.
Definition: ArgException.h:76