ArgException.h
Go to the documentation of this file.
// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*-
/******************************************************************************
*
* file: ArgException.h
*
* Copyright (c) 2003, Michael E. Smoot .
* Copyright (c) 2017 Google LLC
* All rights reserved.
*
* See the file COPYING in the top directory of this distribution for
* more information.
*
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef TCLAP_ARG_EXCEPTION_H
#define TCLAP_ARG_EXCEPTION_H
#include <string>
#include <exception>
namespace TCLAP {
class ArgException : public std::exception
{
public:
ArgException( const std::string& text = "undefined exception",
const std::string& id = "undefined",
const std::string& td = "Generic ArgException")
: std::exception(),
_errorText(text),
_argId( id ),
_typeDescription(td)
{ }
virtual ~ArgException() throw() { }
std::string error() const { return ( _errorText ); }
std::string argId() const
{
if ( _argId == "undefined" )
return " ";
else
return ( "Argument: " + _argId );
}
const char* what() const throw()
{
static std::string ex;
ex = _argId + " -- " + _errorText;
return ex.c_str();
}
std::string typeDescription() const
{
return _typeDescription;
}
private:
std::string _errorText;
std::string _argId;
std::string _typeDescription;
};
class ArgParseException : public ArgException
{
public:
ArgParseException( const std::string& text = "undefined exception",
const std::string& id = "undefined" )
: ArgException( text,
id,
std::string( "Exception found while parsing " ) +
std::string( "the value the Arg has been passed." ))
{ }
};
class CmdLineParseException : public ArgException
{
public:
CmdLineParseException( const std::string& text = "undefined exception",
const std::string& id = "undefined" )
: ArgException( text,
id,
std::string( "Exception found when the values ") +
std::string( "on the command line do not meet ") +
std::string( "the requirements of the defined ") +
std::string( "Args." ))
{ }
};
class SpecificationException : public ArgException
{
public:
SpecificationException( const std::string& text = "undefined exception",
const std::string& id = "undefined" )
: ArgException( text,
id,
std::string("Exception found when an Arg object ")+
std::string("is improperly defined by the ") +
std::string("developer." ))
{ }
};
class ExitException {
public:
ExitException(int estat) : _estat(estat) {}
int getExitStatus() const { return _estat; }
private:
int _estat;
};
} // namespace TCLAP
#endif
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