bpp-core  2.1.0
 All Classes Namespaces Files Functions Variables Typedefs Friends
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 
48 namespace bpp
49 {
50 
56 class Exception:
57  public std::exception
58 {
59  protected:
60  std::string message_;
61 
62  public:
68  Exception(const char* text): message_(std::string(text)) {}
69 
75  Exception(const std::string& text): message_(text) {}
76 
77  virtual ~Exception() throw() {}
78 
79  public:
80 
86  const char* what() const throw() { return message_.c_str(); }
87 };
88 
89 
94  public Exception
95 {
96  public: // Class constructors and destructor:
97 
103  IOException(const char* text): Exception(text) {}
104 
110  IOException(const std::string& text): Exception(text) {}
111 
112  virtual ~IOException() throw() {}
113 
114 };
115 
116 
123  public Exception
124 {
125  public:
126 
132  NullPointerException(const char* text): Exception(text) {}
133 
139  NullPointerException(const std::string& text): Exception(text) {}
140 
141  virtual ~NullPointerException() throw() {}
142 };
143 
144 
149  public Exception
150 {
151  public:
152 
158  ZeroDivisionException(const char* text): Exception(text) {}
159 
165  ZeroDivisionException(const std::string& text): Exception(text) {}
166 
167  virtual ~ZeroDivisionException() throw() {}
168 };
169 
170 
175  public Exception
176 {
177  protected:
178  int badInt_;
179 
180  public:
181 
188  BadIntegerException(const char* text, int badInt);
189 
196  BadIntegerException(const std::string& text, int badInt);
197 
198  virtual ~BadIntegerException() throw() {}
199 
200  public:
201 
207  int getBadInteger() const { return badInt_; }
208 
209 };
210 
211 
216  public Exception
217 {
218  protected:
219  double badNumber_;
220 
221  public:
222 
229  BadNumberException(const char* text, double badNumber);
230 
237  BadNumberException(const std::string& text, double badNumber);
238 
239  virtual ~BadNumberException() throw() {}
240 
241  public:
242 
248  double getBadNumber() const { return badNumber_; }
249 
250 };
251 
252 
257  public Exception
258 {
259  protected:
260  std::string badNumber_;
261 
262  public:
263 
270  NumberFormatException(const char* text, const std::string& badNumber);
271 
278  NumberFormatException(const std::string& text, const std::string& badNumber);
279 
280  virtual ~NumberFormatException() throw() {}
281 
282  public:
283 
289  std::string getBadNumber() const { return badNumber_; }
290 
291 };
292 
293 
298  public virtual Exception
299 {
300  protected:
302 
303  public:
304 
313  IndexOutOfBoundsException(const std::string& text, size_t badInt, size_t lowerBound, size_t upperBound);
314 
315  virtual ~IndexOutOfBoundsException() throw() {}
316 
317  public:
318 
324  std::vector<size_t> getBounds() const;
325 
326  size_t getBadIndex() const { return badIndex_; }
327 };
328 
329 
334  public virtual Exception
335 {
336  protected:
338 
339  public:
340 
348  BadSizeException(const std::string& text, size_t badSize, size_t correctSize);
349 
350  virtual ~BadSizeException() throw() {}
351 
352  public:
353 
354  size_t getBadSize() const { return badSize_; }
355  size_t getCorrectSize() const { return correctSize_; }
356 };
357 
358 
363  public Exception
364 {
365  protected:
367 
368  public:
369 
378  OutOfRangeException(const std::string& text, double badValue, double lowerBound, double upperBound);
379 
380  virtual ~OutOfRangeException() throw() {}
381 
382  public:
383 
387  double getLowerBound() const { return lowerBound_; }
388 
392  double getUpperBound() const { return upperBound_; }
393 };
394 
395 
400  public Exception
401 {
402  public:
403 
409  NotImplementedException(const std::string& text): Exception(text) {}
410 
411  virtual ~NotImplementedException() throw() {}
412 };
413 
414 
415 
416 } //end of namespace bpp.
417 
418 #endif // _EXCEPTIONS_H_
419