BALL  1.4.1
exception.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004    
00005 #ifndef BALL_COMMON_EXCEPTION_H
00006 #define BALL_COMMON_EXCEPTION_H
00007 
00008 #ifndef BALL_CONFIG_CONFIG_H
00009 # include <BALL/CONFIG/config.h>
00010 #endif
00011 
00012 #ifndef BALL_COMMON_GLOBAL_H
00013 # include <BALL/COMMON/global.h>
00014 #endif
00015 
00016 #ifdef BALL_COMPILER_MSVC
00017   #pragma warning(push)
00018   #pragma warning( disable : 4251 ) //disable needs to have dll-interface to be used by clients of class 'std::string'
00019 #endif
00020 
00021 #include <new>
00022 #include <string>
00023 
00024 namespace BALL 
00025 {
00026 
00027   class String;
00028 
00032   namespace Exception 
00033   {
00034     
00059     class BALL_EXPORT GeneralException 
00060       : public std::exception
00061     {
00062       public:
00063 
00067 
00069       GeneralException();
00070       
00072       GeneralException(const char* file, int line);
00073 
00075       GeneralException
00076         (const char* file, int line,
00077          const String& name , const String& message);
00078 
00080       GeneralException(const GeneralException& exception);
00081 
00083       virtual ~GeneralException() throw();
00085 
00089   
00091       const char* getName() const;
00092 
00094       const char* getMessage() const;
00095 
00097       void setMessage(const std::string& message);
00098 
00100       int getLine() const;
00101   
00103       const char* getFile() const;
00105 
00106       protected:
00107       const char* file_;
00108       int         line_;
00109 
00110       std::string name_;
00111       std::string message_;
00112     };    
00113 
00122     class BALL_EXPORT IndexUnderflow 
00123       : public GeneralException
00124     {
00125       public:
00126 
00127       IndexUnderflow(const char* file, int line, Index index = 0, Size size = 0);
00128 
00129 
00130       protected:
00131 
00132       Size size_;
00133       Index index_;
00134     };
00135 
00143     class BALL_EXPORT SizeUnderflow 
00144       : public GeneralException
00145     {
00146       public:
00147 
00148       SizeUnderflow(const char* file, int line, Size size = 0);
00149 
00150       protected:
00151       Size size_;
00152     };
00153 
00162     class BALL_EXPORT IndexOverflow 
00163       : public GeneralException
00164     {
00165       public:
00166       IndexOverflow(const char* file, int line, Index index = 0, Size size = 0);
00167 
00168       protected:
00169 
00170       Size size_;
00171       Index index_;
00172     };
00173 
00177     class BALL_EXPORT InvalidArgument
00178       : public GeneralException
00179     {
00180       public:
00181         InvalidArgument(const char* file, int line, const String& arg);
00182     };
00183 
00187     class BALL_EXPORT InvalidRange 
00188       : public GeneralException
00189     {
00190       public:
00191       InvalidRange(const char* file, int line, float value);
00192     };
00193 
00194 
00201     class BALL_EXPORT InvalidSize 
00202       : public GeneralException
00203     {
00204       public:
00205 
00206       InvalidSize(const char* file, int line, Size size = 0);
00207 
00208       protected:
00209       Size size_;
00210     };
00211 
00212 
00217     class BALL_EXPORT OutOfRange 
00218       : public GeneralException
00219     {
00220       public:
00221       OutOfRange(const char* file, int line);
00222     };
00223 
00229     class BALL_EXPORT InvalidFormat 
00230       : public GeneralException
00231     {
00232       public:
00233       InvalidFormat(const char* file, int line, const String& s);
00234       
00235       ~InvalidFormat() throw();
00236 
00237       protected:
00238 
00239       std::string format_;
00240     };
00241 
00247     class BALL_EXPORT IllegalSelfOperation
00248       : public GeneralException
00249     {
00250       public:
00251       IllegalSelfOperation(const char* file, int line);
00252     };
00253 
00258     class BALL_EXPORT NullPointer 
00259       : public GeneralException
00260     {
00261       public:
00262       NullPointer(const char* file, int line);
00263     };
00264 
00268     class BALL_EXPORT InvalidIterator
00269       : public GeneralException
00270     {
00271       public:
00272       InvalidIterator(const char* file, int line);
00273     };
00274 
00279     class BALL_EXPORT IncompatibleIterators
00280       : public GeneralException
00281     {
00282       public:
00283       IncompatibleIterators(const char* file, int line);
00284     };
00285 
00292     class BALL_EXPORT NotImplemented
00293       : public GeneralException
00294     {
00295       public:
00296       NotImplemented(const char* file, int line);
00297     };
00298 
00303     class BALL_EXPORT IllegalTreeOperation
00304       : public GeneralException
00305     {
00306       public:
00307       IllegalTreeOperation(const char* file, int line);
00308     };
00309 
00316     class BALL_EXPORT OutOfMemory
00317       : public GeneralException, public std::bad_alloc
00318     {
00319       public:
00320       OutOfMemory(const char* file, int line, Size size = 0);
00321       
00322       virtual ~OutOfMemory() 
00323         throw();
00324 
00325       protected:
00326       Size size_;
00327     };
00328 
00331     class BALL_EXPORT BufferOverflow 
00332       : public GeneralException
00333     {
00334       public:
00335       BufferOverflow(const char* file, int line);
00336     };
00337 
00340     class BALL_EXPORT DivisionByZero 
00341       : public GeneralException
00342     {
00343       public:
00344       DivisionByZero(const char* file, int line);
00345     };
00346 
00349     class BALL_EXPORT OutOfGrid 
00350       : public GeneralException
00351     {
00352       public:
00353       OutOfGrid(const char* file, int line);
00354     };
00355 
00359     class BALL_EXPORT FileNotFound 
00360       : public GeneralException
00361     {
00362       public:
00363       FileNotFound(const char* file, int line, const String& filename);
00364 
00365       ~FileNotFound()
00366         throw();
00367       String getFilename() const;
00368 
00369       protected:
00370       std::string filename_;
00371     };
00372 
00376     class BALL_EXPORT IllegalPosition 
00377       : public GeneralException
00378     {
00379       public:
00380       IllegalPosition(const char* file, int line, float x, float y, float z);
00381     };
00382 
00386     class BALL_EXPORT ParseError
00387       : public GeneralException
00388     {
00389       public:
00391       ParseError(const char* file, int line, const String& expression,
00392           const String& message);
00393     };
00394 
00398     class BALL_EXPORT Precondition
00399       : public GeneralException
00400     {
00401       public:
00403       Precondition(const char* file, int line, const char* condition);
00404     };
00405 
00409     class BALL_EXPORT Postcondition
00410       : public GeneralException
00411     {
00412       public:
00414       Postcondition(const char* file, int line, const char* condition);
00415     };
00416 
00418     class BALL_EXPORT InvalidOption: public Exception::GeneralException
00419     {
00420       public:
00421 
00423         InvalidOption(const char* file, int line, String option);
00424     };
00425     
00427     class BALL_EXPORT TooManyErrors
00428       : public Exception::GeneralException
00429     {
00430       public:
00432       TooManyErrors(const char* file, int line);
00433     };
00434      
00436     class BALL_EXPORT TooManyBonds
00437       : public Exception::GeneralException
00438     {
00439       public:
00441       TooManyBonds(const char* file, int line, const String& error);
00442     };
00443     
00447     class BALL_EXPORT CUDAError 
00448       : public Exception::GeneralException
00449     {
00450       public:
00451       CUDAError(const char* file, int line, const String& error);                 
00452     };
00453 
00461     class BALL_EXPORT NoBufferAvailable 
00462       : public Exception::GeneralException
00463     {
00464     public:
00465       NoBufferAvailable(const char* file, int line, const String& reason);
00466     };
00467 
00473     class BALL_EXPORT FormatUnsupported
00474       : public Exception::GeneralException
00475     {
00476     public:
00477       FormatUnsupported(const char* file, int line);
00478     };
00479 
00482     class BALL_EXPORT GlobalExceptionHandler
00483     {
00484       public:
00488 
00505       GlobalExceptionHandler();
00507       
00511         
00513       static void setName(const String& name);
00514         
00516       static void setMessage(const String& message);
00517 
00519       static void setLine(int line);
00520 
00522       static void setFile(const String& file);
00523 
00525       static void set
00526         (const String& file, int line, 
00527          const String& name, const String& message);
00529       
00530       protected:
00531 
00533       static void terminate();
00534 
00536       static void newHandler() throw(Exception::OutOfMemory);
00537 
00538       static std::string file_;
00539       static int         line_;
00540       static std::string name_;
00541       static std::string message_;
00542     };
00543 
00546     BALL_EXPORT extern GlobalExceptionHandler globalHandler;
00547 
00548   }
00567     BALL_EXPORT
00568     std::ostream& operator << (std::ostream& os, const Exception::GeneralException& e);
00569   
00570 } // namespace BALL
00571 
00572 #ifdef BALL_COMPILER_MSVC
00573   #pragma warning(pop)
00574 #endif
00575 
00576 #endif // BALL_COMMON_EXCEPTION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines