bpp-core3  3.0.0
Exceptions.h
Go to the documentation of this file.
1 //
2 // File: Exceptions.h
3 // Authors:
4 // Guillaume Deuchst
5 // Julien Dutheil
6 // Sylvain Gaillard
7 // Francois Gindraud (2017)
8 // Last modified: 2017-06-26 00:00:00
9 //
10 
11 /*
12  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
13 
14  This software is a computer program whose purpose is to provide utilitary
15  classes. This file belongs to the Bio++ Project.
16 
17  This software is governed by the CeCILL license under French law and
18  abiding by the rules of distribution of free software. You can use,
19  modify and/ or redistribute the software under the terms of the CeCILL
20  license as circulated by CEA, CNRS and INRIA at the following URL
21  "http://www.cecill.info".
22 
23  As a counterpart to the access to the source code and rights to copy,
24  modify and redistribute granted by the license, users are provided only
25  with a limited warranty and the software's author, the holder of the
26  economic rights, and the successive licensors have only limited
27  liability.
28 
29  In this respect, the user's attention is drawn to the risks associated
30  with loading, using, modifying and/or developing or reproducing the
31  software by the user in light of its specific status of free software,
32  that may mean that it is complicated to manipulate, and that also
33  therefore means that it is reserved for developers and experienced
34  professionals having in-depth computer knowledge. Users are therefore
35  encouraged to load and test the software's suitability as regards their
36  requirements in conditions enabling the security of their systems and/or
37  data to be ensured and, more generally, to use and operate it in the
38  same conditions as regards security.
39 
40  The fact that you are presently reading this means that you have had
41  knowledge of the CeCILL license and that you accept its terms.
42 */
43 
44 #ifndef BPP_EXCEPTIONS_H
45 #define BPP_EXCEPTIONS_H
46 
47 #include <array>
48 #include <stdexcept>
49 #include <string>
50 
51 
52 namespace bpp
53 {
58 class Exception : public std::exception
59 {
60 private:
61  std::string message_;
62 
63 public:
70  Exception(std::string text, int stack = 10);
74  const char* what() const noexcept override;
76  const std::string& message() const noexcept;
77 };
78 
80 class IOException : public Exception
81 {
82 public:
87  IOException(std::string text);
88 };
89 
95 {
96 public:
101  NullPointerException(std::string text);
102 };
103 
106 {
107 public:
111  ZeroDivisionException(std::string text);
112 };
113 
116 {
117 private:
118  int badInt_;
119 
120 public:
125  BadIntegerException(std::string text, int badInt);
129  int getBadInteger() const;
130 };
131 
134 {
135 private:
136  double badNumber_;
137 
138 public:
143  BadNumberException(std::string text, double badNumber);
147  double getBadNumber() const;
148 };
149 
152 {
153 private:
154  std::string badNumber_;
155 
156 public:
161  NumberFormatException(std::string text, std::string badNumber);
165  const std::string& getBadNumber() const;
166 };
167 
170 {
171 private:
172  std::size_t badIndex_;
173  std::array<std::size_t, 2> bounds_;
174 
175 public:
182  IndexOutOfBoundsException(std::string text, std::size_t badInt, std::size_t lowerBound, std::size_t upperBound);
184  const std::array<std::size_t, 2>& getBounds() const;
185  std::size_t getBadIndex() const;
186 };
187 
190 {
191 private:
192  std::size_t badSize_;
193  std::size_t correctSize_;
194 
195 public:
201  BadSizeException(std::string text, std::size_t badSize, std::size_t correctSize);
202 
203  std::size_t getBadSize() const;
204  std::size_t getCorrectSize() const;
205 };
206 
209 {
210 private:
211  double badValue_;
212  std::array<double, 2> bounds_;
213 
214 public:
221  OutOfRangeException(std::string text, double badValue, double lowerBound, double upperBound);
222 
223  double getBadValue () const;
224  double getLowerBound() const;
225  double getUpperBound() const;
226 };
227 
230 {
231 public:
235  NotImplementedException(std::string text);
236 };
237 } // namespace bpp
238 #endif // BPP_EXCEPTIONS_H
Number exception: integers.
Definition: Exceptions.h:116
Number exception: doubles.
Definition: Exceptions.h:134
Wrong size exception class.
Definition: Exceptions.h:190
std::size_t badSize_
Definition: Exceptions.h:192
std::size_t correctSize_
Definition: Exceptions.h:193
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
const char * what() const noexcept override
Method to get the message of the exception (STL method redefinition).
Definition: Exceptions.cpp:118
const std::string & message() const noexcept
Access the message as a std::string.
Definition: Exceptions.cpp:119
std::string message_
Definition: Exceptions.h:61
Exception(std::string text, int stack=10)
Build a new Exception.
Definition: Exceptions.cpp:56
The base class exception for IO error.
Definition: Exceptions.h:81
Index out of bounds exception class.
Definition: Exceptions.h:170
std::array< std::size_t, 2 > bounds_
Definition: Exceptions.h:173
This exception is sent when a given method is not implemented.
Definition: Exceptions.h:230
The base class exception for NULL pointer error. This exception may be thrown when an unexpected NULL...
Definition: Exceptions.h:95
Number format exception.
Definition: Exceptions.h:152
Out of range exception class.
Definition: Exceptions.h:209
std::array< double, 2 > bounds_
Definition: Exceptions.h:212
The base class exception for zero division error.
Definition: Exceptions.h:106