bpp-core  2.2.0
Exceptions.h
Go to the documentation of this file.
1 //
2 // File Exceptions.h
3 // Created by: Guillaume Deuchst
4 // Julien Dutheil
5 // Sylvain Gaillard
6 // Last modification : Thu Jul 22 2004
7 //
8 
9 /*
10 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11 
12 This software is a computer program whose purpose is to provide utilitary
13 classes. This file belongs to the Bio++ Project.
14 
15 This software is governed by the CeCILL license under French law and
16 abiding by the rules of distribution of free software. You can use,
17 modify and/ or redistribute the software under the terms of the CeCILL
18 license as circulated by CEA, CNRS and INRIA at the following URL
19 "http://www.cecill.info".
20 
21 As a counterpart to the access to the source code and rights to copy,
22 modify and redistribute granted by the license, users are provided only
23 with a limited warranty and the software's author, the holder of the
24 economic rights, and the successive licensors have only limited
25 liability.
26 
27 In this respect, the user's attention is drawn to the risks associated
28 with loading, using, modifying and/or developing or reproducing the
29 software by the user in light of its specific status of free software,
30 that may mean that it is complicated to manipulate, and that also
31 therefore means that it is reserved for developers and experienced
32 professionals having in-depth computer knowledge. Users are therefore
33 encouraged to load and test the software's suitability as regards their
34 requirements in conditions enabling the security of their systems and/or
35 data to be ensured and, more generally, to use and operate it in the
36 same conditions as regards security.
37 
38 The fact that you are presently reading this means that you have had
39 knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #ifndef _EXCEPTIONS_H_
43 #define _EXCEPTIONS_H_
44 
45 #include <stdexcept>
46 #include <vector>
47 #include <string>
48 
49 namespace bpp
50 {
51 
57 class Exception:
58  public std::exception
59 {
60  protected:
61  std::string message_;
62 
63  public:
69  Exception(const char* text): message_(std::string(text)) {}
70 
76  Exception(const std::string& text): message_(text) {}
77 
78  virtual ~Exception() throw() {}
79 
80  public:
81 
87  const char* what() const throw() { return message_.c_str(); }
88 };
89 
90 
95  public Exception
96 {
97  public: // Class constructors and destructor:
98 
104  IOException(const char* text): Exception(text) {}
105 
111  IOException(const std::string& text): Exception(text) {}
112 
113  virtual ~IOException() throw() {}
114 
115 };
116 
117 
124  public Exception
125 {
126  public:
127 
133  NullPointerException(const char* text): Exception(text) {}
134 
140  NullPointerException(const std::string& text): Exception(text) {}
141 
142  virtual ~NullPointerException() throw() {}
143 };
144 
145 
150  public Exception
151 {
152  public:
153 
159  ZeroDivisionException(const char* text): Exception(text) {}
160 
166  ZeroDivisionException(const std::string& text): Exception(text) {}
167 
168  virtual ~ZeroDivisionException() throw() {}
169 };
170 
171 
176  public Exception
177 {
178  protected:
179  int badInt_;
180 
181  public:
182 
189  BadIntegerException(const char* text, int badInt);
190 
197  BadIntegerException(const std::string& text, int badInt);
198 
199  virtual ~BadIntegerException() throw() {}
200 
201  public:
202 
208  int getBadInteger() const { return badInt_; }
209 
210 };
211 
212 
217  public Exception
218 {
219  protected:
220  double badNumber_;
221 
222  public:
223 
230  BadNumberException(const char* text, double badNumber);
231 
238  BadNumberException(const std::string& text, double badNumber);
239 
240  virtual ~BadNumberException() throw() {}
241 
242  public:
243 
249  double getBadNumber() const { return badNumber_; }
250 
251 };
252 
253 
258  public Exception
259 {
260  protected:
261  std::string badNumber_;
262 
263  public:
264 
271  NumberFormatException(const char* text, const std::string& badNumber);
272 
279  NumberFormatException(const std::string& text, const std::string& badNumber);
280 
281  virtual ~NumberFormatException() throw() {}
282 
283  public:
284 
290  std::string getBadNumber() const { return badNumber_; }
291 
292 };
293 
294 
299  public virtual Exception
300 {
301  protected:
303 
304  public:
305 
314  IndexOutOfBoundsException(const std::string& text, size_t badInt, size_t lowerBound, size_t upperBound);
315 
316  virtual ~IndexOutOfBoundsException() throw() {}
317 
318  public:
319 
325  std::vector<size_t> getBounds() const;
326 
327  size_t getBadIndex() const { return badIndex_; }
328 };
329 
330 
335  public virtual Exception
336 {
337  protected:
339 
340  public:
341 
349  BadSizeException(const std::string& text, size_t badSize, size_t correctSize);
350 
351  virtual ~BadSizeException() throw() {}
352 
353  public:
354 
355  size_t getBadSize() const { return badSize_; }
356  size_t getCorrectSize() const { return correctSize_; }
357 };
358 
359 
364  public Exception
365 {
366  protected:
368 
369  public:
370 
379  OutOfRangeException(const std::string& text, double badValue, double lowerBound, double upperBound);
380 
381  virtual ~OutOfRangeException() throw() {}
382 
383  public:
384 
388  double getLowerBound() const { return lowerBound_; }
389 
393  double getUpperBound() const { return upperBound_; }
394 };
395 
396 
401  public Exception
402 {
403  public:
404 
410  NotImplementedException(const std::string& text): Exception(text) {}
411 
412  virtual ~NotImplementedException() throw() {}
413 };
414 
415 
416 
417 } //end of namespace bpp.
418 
419 #endif // _EXCEPTIONS_H_
420 
virtual ~Exception()
Definition: Exceptions.h:78
size_t getBadSize() const
Definition: Exceptions.h:355
Number exception: doubles.
Definition: Exceptions.h:216
The base class exception for zero division error.
Definition: Exceptions.h:149
The base class exception for IO error.
Definition: Exceptions.h:94
virtual ~ZeroDivisionException()
Definition: Exceptions.h:168
OutOfRangeException(const std::string &text, double badValue, double lowerBound, double upperBound)
Build a new OutOfRangeException.
Definition: Exceptions.cpp:103
This class allows to perform a correspondence analysis.
Number exception: integers.
Definition: Exceptions.h:175
Exception(const std::string &text)
Build a new Exception.
Definition: Exceptions.h:76
STL namespace.
std::string getBadNumber() const
Get the number that threw this exception.
Definition: Exceptions.h:290
double getUpperBound() const
Definition: Exceptions.h:393
ZeroDivisionException(const char *text)
Build a new ZeroDivisionException.
Definition: Exceptions.h:159
Exception(const char *text)
Build a new Exception.
Definition: Exceptions.h:69
double getLowerBound() const
Definition: Exceptions.h:388
virtual ~NumberFormatException()
Definition: Exceptions.h:281
int getBadInteger() const
Get the integer that threw this exception.
Definition: Exceptions.h:208
ZeroDivisionException(const std::string &text)
Build a new ZeroDivisionException.
Definition: Exceptions.h:166
virtual ~OutOfRangeException()
Definition: Exceptions.h:381
std::vector< size_t > getBounds() const
Get the bounds.
Definition: Exceptions.cpp:86
Wrong size exception class.
Definition: Exceptions.h:334
IndexOutOfBoundsException(const std::string &text, size_t badInt, size_t lowerBound, size_t upperBound)
Build a new IndexOutOfBoundsException.
Definition: Exceptions.cpp:80
IOException(const char *text)
Build a new IOException.
Definition: Exceptions.h:104
virtual ~BadSizeException()
Definition: Exceptions.h:351
double getBadNumber() const
Get the number that threw this exception.
Definition: Exceptions.h:249
This expeption is sent when a given method is not implemented.
Definition: Exceptions.h:400
virtual ~BadNumberException()
Definition: Exceptions.h:240
BadSizeException(const std::string &text, size_t badSize, size_t correctSize)
Build a new BadSizeException.
Definition: Exceptions.cpp:96
size_t getCorrectSize() const
Definition: Exceptions.h:356
std::string message_
Definition: Exceptions.h:61
const char * what() const
Method to get the message of the exception (STL method redefinition).
Definition: Exceptions.h:87
The base class exception for NULL pointer error.
Definition: Exceptions.h:123
virtual ~BadIntegerException()
Definition: Exceptions.h:199
BadIntegerException(const char *text, int badInt)
Build a new BadIntegerException.
Definition: Exceptions.cpp:50
NullPointerException(const std::string &text)
Build a new NullPointerException.
Definition: Exceptions.h:140
Out of range exception class.
Definition: Exceptions.h:363
Exception base class.
Definition: Exceptions.h:57
IOException(const std::string &text)
Build a new IOException.
Definition: Exceptions.h:111
NullPointerException(const char *text)
Build a new NullPointerException.
Definition: Exceptions.h:133
NotImplementedException(const std::string &text)
Build a new NotImplementedException.
Definition: Exceptions.h:410
Number format exception.
Definition: Exceptions.h:257
NumberFormatException(const char *text, const std::string &badNumber)
Build a new NumberFormatException.
Definition: Exceptions.cpp:70
BadNumberException(const char *text, double badNumber)
Build a new BadNumberException.
Definition: Exceptions.cpp:60
Index out of bounds exception class.
Definition: Exceptions.h:298
virtual ~NullPointerException()
Definition: Exceptions.h:142
virtual ~IOException()
Definition: Exceptions.h:113