bpp-core3  3.0.0
ParameterExceptions.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "Parameter.h"
6 #include "ParameterExceptions.h"
7 
8 // From Utils:
9 #include "../Text/TextTools.h"
10 
11 using namespace bpp;
12 using namespace std;
13 
14 /******************************************************************************/
15 
16 ParameterException::ParameterException(const std::string& text, const Parameter* param) :
17  Exception("ParameterException: " + text + (param != 0 ? "(" + param->getName() + ")" : string(""))),
18  parameter_(param) {}
19 
21 
22 /******************************************************************************/
23 
24 ConstraintException::ConstraintException(const std::string& text, const Parameter* param, double badValue) :
25  ParameterException("ConstraintException: " + text + "(" + TextTools::toString(badValue) + ")"
26  + (param->hasConstraint() ? param->getConstraint()->getDescription() : "no constraint"), param),
27  badValue_(badValue) {}
28 
29 double ConstraintException::getBadValue() const { return badValue_; }
30 
31 /******************************************************************************/
32 
33 ParameterNotFoundException::ParameterNotFoundException(const string& text, const string& param) :
34  Exception("ParameterNotFoundException: " + text + (!TextTools::isEmpty(param) ? "(" + param + ")" : string(""))),
35  parameter_(param) {}
36 
37 std::string ParameterNotFoundException::parameter() const { return parameter_; }
38 
39 /******************************************************************************/
ConstraintException(const std::string &text, const Parameter *param, double badValue)
Build a new ConstraintException object.
ParameterException(const std::string &text, const Parameter *param)
Build a new ParameterException object.
virtual const Parameter * parameter() const
Get the parameter that threw the exception.
const Parameter * parameter_
ParameterNotFoundException(const std::string &text, const std::string &param="")
Build a new ParameterNotFoundException object.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
virtual double getBadValue() const
Get the value that doesn't match the constraint.
virtual std::string parameter() const
Get the name of the parameter not found.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
bool isEmpty(const std::string &s)
Tell if a string is empty. A string is considered to be 'empty' if it is only made of white spaces...
Definition: TextTools.cpp:20
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:115
The parameter exception base class.