BALL  1.5.0
COMMON/exception.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_COMMON_EXCEPTION_H
6 #define BALL_COMMON_EXCEPTION_H
7 
8 #ifndef BALL_CONFIG_CONFIG_H
9 # include <BALL/CONFIG/config.h>
10 #endif
11 
12 #ifndef BALL_COMMON_GLOBAL_H
13 # include <BALL/COMMON/global.h>
14 #endif
15 
16 #ifdef BALL_COMPILER_MSVC
17  #pragma warning(push)
18  #pragma warning( disable : 4251 ) //disable needs to have dll-interface to be used by clients of class 'std::string'
19 #endif
20 
21 #include <new>
22 #include <string>
23 
24 namespace BALL
25 {
26 
27  class String;
28 
32  namespace Exception
33  {
34 
60  : public std::exception
61  {
62  public:
63 
67 
70 
72  GeneralException(const char* file, int line);
73 
76  (const char* file, int line,
77  const String& name , const String& message);
78 
81 
83  virtual ~GeneralException() throw();
85 
89 
91  const char* getName() const;
92 
94  const char* getMessage() const;
95 
97  void setMessage(const std::string& message);
98 
100  int getLine() const;
101 
103  const char* getFile() const;
105 
106  protected:
107  const char* file_;
108  int line_;
109 
110  std::string name_;
111  std::string message_;
112  };
113 
123  : public GeneralException
124  {
125  public:
126 
127  IndexUnderflow(const char* file, int line, Index index = 0, Size size = 0);
128 
129 
130  protected:
131 
134  };
135 
144  : public GeneralException
145  {
146  public:
147 
148  SizeUnderflow(const char* file, int line, Size size = 0);
149 
150  protected:
152  };
153 
163  : public GeneralException
164  {
165  public:
166  IndexOverflow(const char* file, int line, Index index = 0, Size size = 0);
167 
168  protected:
169 
172  };
173 
178  : public GeneralException
179  {
180  public:
181  InvalidArgument(const char* file, int line, const String& arg);
182  };
183 
188  : public GeneralException
189  {
190  public:
191  InvalidRange(const char* file, int line, float value);
192  };
193 
194 
202  : public GeneralException
203  {
204  public:
205 
206  InvalidSize(const char* file, int line, Size size = 0);
207 
208  protected:
210  };
211 
212 
218  : public GeneralException
219  {
220  public:
221  OutOfRange(const char* file, int line);
222  };
223 
230  : public GeneralException
231  {
232  public:
233  InvalidFormat(const char* file, int line, const String& s);
234 
235  ~InvalidFormat() throw();
236 
237  protected:
238 
239  std::string format_;
240  };
241 
248  : public GeneralException
249  {
250  public:
251  IllegalSelfOperation(const char* file, int line);
252  };
253 
259  : public GeneralException
260  {
261  public:
262  NullPointer(const char* file, int line);
263  };
264 
269  : public GeneralException
270  {
271  public:
272  InvalidIterator(const char* file, int line);
273  };
274 
280  : public GeneralException
281  {
282  public:
283  IncompatibleIterators(const char* file, int line);
284  };
285 
293  : public GeneralException
294  {
295  public:
296  NotImplemented(const char* file, int line);
297  };
298 
304  : public GeneralException
305  {
306  public:
307  IllegalTreeOperation(const char* file, int line);
308  };
309 
317  : public GeneralException, public std::bad_alloc
318  {
319  public:
320  OutOfMemory(const char* file, int line, Size size = 0);
321 
322  virtual ~OutOfMemory()
323  throw();
324 
325  protected:
326  Size size_;
327  };
328 
332  : public GeneralException
333  {
334  public:
335  BufferOverflow(const char* file, int line);
336  };
337 
341  : public GeneralException
342  {
343  public:
344  DivisionByZero(const char* file, int line);
345  };
346 
350  : public GeneralException
351  {
352  public:
353  OutOfGrid(const char* file, int line);
354  };
355 
360  : public GeneralException
361  {
362  public:
363  FileNotFound(const char* file, int line, const String& filename);
364 
366  throw();
367  String getFilename() const;
368 
369  protected:
370  std::string filename_;
371  };
372 
377  : public GeneralException
378  {
379  public:
380  IllegalPosition(const char* file, int line, float x, float y, float z);
381  };
382 
387  : public GeneralException
388  {
389  public:
391  ParseError(const char* file, int line, const String& expression,
392  const String& message);
393  };
394 
399  : public GeneralException
400  {
401  public:
403  Precondition(const char* file, int line, const char* condition);
404  };
405 
410  : public GeneralException
411  {
412  public:
414  Postcondition(const char* file, int line, const char* condition);
415  };
416 
419  {
420  public:
421 
423  InvalidOption(const char* file, int line, String option);
424  };
425 
429  {
430  public:
432  TooManyErrors(const char* file, int line);
433  };
434 
438  {
439  public:
441  TooManyBonds(const char* file, int line, const String& error);
442  };
443 
449  {
450  public:
451  CUDAError(const char* file, int line, const String& error);
452  };
453 
463  {
464  public:
465  NoBufferAvailable(const char* file, int line, const String& reason);
466  };
467 
475  {
476  public:
477  FormatUnsupported(const char* file, int line);
478  };
479 
486  {
487  public:
488  NotInitialized(const char* file, int line, const String& reason);
489  };
490 
494  {
495  public:
499 
518 
522 
524  static void setName(const String& name);
525 
527  static void setMessage(const String& message);
528 
530  static void setLine(int line);
531 
533  static void setFile(const String& file);
534 
536  static void set
537  (const String& file, int line,
538  const String& name, const String& message);
540 
541  protected:
542 
544  static void terminate();
545 
549  static void newHandler();
550 
551  static std::string file_;
552  static int line_;
553  static std::string name_;
554  static std::string message_;
555  };
556 
560 
561  }
581  std::ostream& operator << (std::ostream& os, const Exception::GeneralException& e);
582 
583 } // namespace BALL
584 
585 #ifdef BALL_COMPILER_MSVC
586  #pragma warning(pop)
587 #endif
588 
589 #endif // BALL_COMMON_EXCEPTION_H
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
Definition: constants.h:13
BALL_INDEX_TYPE Index
BALL_EXPORT GlobalExceptionHandler globalHandler
const char * getName()
Definition: rtti.h:97
virtual ~GeneralException()
Destructor.
GeneralException()
Default constructor.
GeneralException(const char *file, int line, const String &name, const String &message)
Constructor.
GeneralException(const char *file, int line)
Constructor.
GeneralException(const GeneralException &exception)
Copy constructor.
IndexUnderflow(const char *file, int line, Index index=0, Size size=0)
SizeUnderflow(const char *file, int line, Size size=0)
IndexOverflow(const char *file, int line, Index index=0, Size size=0)
InvalidArgument(const char *file, int line, const String &arg)
InvalidRange(const char *file, int line, float value)
InvalidSize(const char *file, int line, Size size=0)
OutOfRange(const char *file, int line)
InvalidFormat(const char *file, int line, const String &s)
IllegalSelfOperation(const char *file, int line)
NullPointer(const char *file, int line)
InvalidIterator(const char *file, int line)
IncompatibleIterators(const char *file, int line)
NotImplemented(const char *file, int line)
IllegalTreeOperation(const char *file, int line)
OutOfMemory(const char *file, int line, Size size=0)
BufferOverflow(const char *file, int line)
DivisionByZero(const char *file, int line)
OutOfGrid(const char *file, int line)
FileNotFound(const char *file, int line, const String &filename)
IllegalPosition(const char *file, int line, float x, float y, float z)
ParseError(const char *file, int line, const String &expression, const String &message)
Precondition(const char *file, int line, const char *condition)
Postcondition(const char *file, int line, const char *condition)
Exception to be thrown if an invalid option is given.
InvalidOption(const char *file, int line, String option)
Exception to be thrown if too many errors occur, e.g. in ForceField.
TooManyErrors(const char *file, int line)
Exception to be thrown if too many bonds for one atom.
TooManyBonds(const char *file, int line, const String &error)
CUDAError(const char *file, int line, const String &error)
NoBufferAvailable(const char *file, int line, const String &reason)
FormatUnsupported(const char *file, int line)
NotInitialized(const char *file, int line, const String &reason)
static void set(const String &file, int line, const String &name, const String &message)
Set all exception attributes.
static void setFile(const String &file)
The source file name where the exception was thrown.
static void setName(const String &name)
Assign the name of the exception. This should agree with the class name.
static void setLine(int line)
Set the line number the exception was thrown. Should be set to LINE in most cases.
static void terminate()
The BALL replacement for terminate.
static void setMessage(const String &message)
Set the error message.
#define BALL_DEPRECATED
Definition: COMMON/global.h:64
#define BALL_EXPORT
Definition: COMMON/global.h:50