tclap  1.2.2
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 
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 
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 
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 
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 
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:177
A simple class that defines and argument exception.
Definition: ArgException.h:37
Thrown from CmdLine when the arguments on the command line are not properly specified, e.g.
Definition: ArgException.h:144
virtual ~ArgException()
Destructor.
Definition: ArgException.h:60
std::string argId() const
Returns the argument id.
Definition: ArgException.h:70
ArgException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
Definition: ArgException.h:48
ExitException(int estat)
Definition: ArgException.h:202
Thrown when TCLAP thinks the program should exit.
Definition: ArgException.h:200
std::string typeDescription() const
Returns the type of the exception.
Definition: ArgException.h:92
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: ArgException.h:168
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:131
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition: ArgException.h:153
int getExitStatus() const
Definition: ArgException.h:204
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
Definition: ArgException.h:122
Definition: Arg.h:48
std::string error() const
Returns the error text.
Definition: ArgException.h:65
const char * what() const
Returns the arg id and error text.
Definition: ArgException.h:81