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 * All rights reserved.
9 *
10 * See the file COPYING in the top directory of this distribution for
11 * more information.
12 *
13 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 * DEALINGS IN THE SOFTWARE.
20 *
21 *****************************************************************************/
22
23
24#ifndef TCLAP_ARG_EXCEPTION_H
25#define TCLAP_ARG_EXCEPTION_H
26
27#include <string>
28#include <exception>
29
30namespace TCLAP {
31
36class ArgException : public std::exception
37{
38 public:
39
47 ArgException( const std::string& text = "undefined exception",
48 const std::string& id = "undefined",
49 const std::string& td = "Generic ArgException")
50 : std::exception(),
51 _errorText(text),
52 _argId( id ),
53 _typeDescription(td)
54 { }
55
59 virtual ~ArgException() throw() { }
60
64 std::string error() const { return ( _errorText ); }
65
69 std::string argId() const
70 {
71 if ( _argId == "undefined" )
72 return " ";
73 else
74 return ( "Argument: " + _argId );
75 }
76
80 const char* what() const throw()
81 {
82 static std::string ex;
83 ex = _argId + " -- " + _errorText;
84 return ex.c_str();
85 }
86
91 std::string typeDescription() const
92 {
93 return _typeDescription;
94 }
95
96
97 private:
98
102 std::string _errorText;
103
107 std::string _argId;
108
113 std::string _typeDescription;
114
115};
116
122{
123 public:
130 ArgParseException( const std::string& text = "undefined exception",
131 const std::string& id = "undefined" )
132 : ArgException( text,
133 id,
134 std::string( "Exception found while parsing " ) +
135 std::string( "the value the Arg has been passed." ))
136 { }
137};
138
144{
145 public:
152 CmdLineParseException( const std::string& text = "undefined exception",
153 const std::string& id = "undefined" )
154 : ArgException( text,
155 id,
156 std::string( "Exception found when the values ") +
157 std::string( "on the command line do not meet ") +
158 std::string( "the requirements of the defined ") +
159 std::string( "Args." ))
160 { }
161};
162
168{
169 public:
176 SpecificationException( const std::string& text = "undefined exception",
177 const std::string& id = "undefined" )
178 : ArgException( text,
179 id,
180 std::string("Exception found when an Arg object ")+
181 std::string("is improperly defined by the ") +
182 std::string("developer." ))
183 { }
184
185};
186
188public:
189 ExitException(int estat) : _estat(estat) {}
190
191 int getExitStatus() const { return _estat; }
192
193private:
194 int _estat;
195};
196
197} // namespace TCLAP
198
199#endif
200
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.
ArgParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
CmdLineParseException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
int getExitStatus() const
SpecificationException(const std::string &text="undefined exception", const std::string &id="undefined")
Constructor.
Definition Arg.h:58