exception.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: exception.h,v 1.51 2005/12/23 17:01:39 amoll Exp $
00005 //
00006    
00007 #ifndef BALL_COMMON_EXCEPTION_H
00008 #define BALL_COMMON_EXCEPTION_H
00009 
00010 #ifndef BALL_CONFIG_CONFIG_H
00011 # include <BALL/CONFIG/config.h>
00012 #endif
00013 
00014 #ifndef BALL_COMMON_GLOBAL_H
00015 # include <BALL/COMMON/global.h>
00016 #endif
00017 
00018 #include <new>
00019 #include <string>
00020 
00021 namespace BALL 
00022 {
00023 
00024   class String;
00025 
00029   namespace Exception 
00030   {
00031     
00056     class BALL_EXPORT GeneralException 
00057       : public std::exception
00058     {
00059       public:
00060 
00064 
00066       GeneralException()
00067         ;
00068       
00070       GeneralException(const char* file, int line)
00071         ;
00072 
00074       GeneralException
00075         (const char* file, int line,
00076          const String& name , const String& message)
00077         ;
00078 
00080       GeneralException(const GeneralException& exception)
00081         ;
00082 
00084       virtual ~GeneralException() throw();
00086 
00090   
00092       const char* getName() const
00093         ;
00094 
00096       const char* getMessage() const
00097         ;
00098 
00100       void setMessage(const std::string& message)
00101         ;
00102 
00104       int getLine() const
00105         ;
00106   
00108       const char* getFile() const
00109         ;
00111 
00112       protected:
00113       const char* file_;
00114       int         line_;
00115 
00116       std::string name_;
00117       std::string message_;
00118     };    
00119 
00128     class BALL_EXPORT IndexUnderflow 
00129       : public GeneralException
00130     {
00131       public:
00132 
00133       IndexUnderflow(const char* file, int line, Index index = 0, Size size = 0)
00134         ;
00135 
00136 
00137       protected:
00138 
00139       Size size_;
00140       Index index_;
00141     };
00142 
00150     class BALL_EXPORT SizeUnderflow 
00151       : public GeneralException
00152     {
00153       public:
00154 
00155       SizeUnderflow(const char* file, int line, Size size = 0)
00156         ;
00157 
00158       protected:
00159       Size size_;
00160     };
00161 
00170     class BALL_EXPORT IndexOverflow 
00171       : public GeneralException
00172     {
00173       public:
00174       IndexOverflow(const char* file, int line, Index index = 0, Size size = 0)
00175         ;
00176 
00177       protected:
00178 
00179       Size size_;
00180       Index index_;
00181     };
00182 
00186     class BALL_EXPORT InvalidArgument
00187       : public GeneralException
00188     {
00189       public:
00190         InvalidArgument(const char* file, int line, const String& arg);
00191     };
00192 
00196     class BALL_EXPORT InvalidRange 
00197       : public GeneralException
00198     {
00199       public:
00200       InvalidRange(const char* file, int line, float value)
00201         ;
00202     };
00203 
00204 
00211     class BALL_EXPORT InvalidSize 
00212       : public GeneralException
00213     {
00214       public:
00215 
00216       InvalidSize(const char* file, int line, Size size = 0)
00217         ;
00218 
00219       protected:
00220       Size size_;
00221     };
00222 
00223 
00228     class BALL_EXPORT OutOfRange 
00229       : public GeneralException
00230     {
00231       public:
00232       OutOfRange(const char* file, int line)
00233         ;
00234     };
00235 
00241     class BALL_EXPORT InvalidFormat 
00242       : public GeneralException
00243     {
00244       public:
00245       InvalidFormat(const char* file, int line, const String& s)
00246         ;
00247       
00248       ~InvalidFormat()
00249         throw();
00250 
00251       protected:
00252 
00253       std::string format_;
00254     };
00255 
00261     class BALL_EXPORT IllegalSelfOperation
00262       : public GeneralException
00263     {
00264       public:
00265       IllegalSelfOperation(const char* file, int line)
00266         ;
00267     };
00268 
00273     class BALL_EXPORT NullPointer 
00274       : public GeneralException
00275     {
00276       public:
00277       NullPointer(const char* file, int line)
00278         ;
00279     };
00280 
00284     class BALL_EXPORT InvalidIterator
00285       : public GeneralException
00286     {
00287       public:
00288       InvalidIterator(const char* file, int line)
00289         ;
00290     };
00291 
00296     class BALL_EXPORT IncompatibleIterators
00297       : public GeneralException
00298     {
00299       public:
00300       IncompatibleIterators(const char* file, int line)
00301         ;
00302     };
00303 
00310     class BALL_EXPORT NotImplemented
00311       : public GeneralException
00312     {
00313       public:
00314       NotImplemented(const char* file, int line)
00315         ;
00316     };
00317 
00322     class BALL_EXPORT IllegalTreeOperation
00323       : public GeneralException
00324     {
00325       public:
00326       IllegalTreeOperation(const char* file, int line)
00327         ;
00328     };
00329 
00336     class BALL_EXPORT OutOfMemory
00337       : public GeneralException, public std::bad_alloc
00338     {
00339       public:
00340       OutOfMemory(const char* file, int line, Size size = 0)
00341         ;
00342       
00343       virtual ~OutOfMemory() 
00344         throw();
00345 
00346       protected:
00347       Size size_;
00348     };
00349 
00352     class BALL_EXPORT BufferOverflow 
00353       : public GeneralException
00354     {
00355       public:
00356       BufferOverflow(const char* file, int line)
00357         ;
00358     };
00359 
00362     class BALL_EXPORT DivisionByZero 
00363       : public GeneralException
00364     {
00365       public:
00366       DivisionByZero(const char* file, int line)
00367         ;
00368     };
00369 
00372     class BALL_EXPORT OutOfGrid 
00373       : public GeneralException
00374     {
00375       public:
00376       OutOfGrid(const char* file, int line)
00377         ;
00378     };
00379 
00383     class BALL_EXPORT FileNotFound 
00384       : public GeneralException
00385     {
00386       public:
00387       FileNotFound(const char* file, int line, const String& filename)
00388         ;
00389 
00390       ~FileNotFound()
00391         throw();
00392       String getFilename() const
00393         ;
00394 
00395       protected:
00396       std::string filename_;
00397     };
00398 
00402     class BALL_EXPORT IllegalPosition 
00403       : public GeneralException
00404     {
00405       public:
00406       IllegalPosition(const char* file, int line, float x, float y, float z)
00407         ;
00408     };
00409 
00413     class BALL_EXPORT ParseError
00414       : public GeneralException
00415     {
00416       public:
00418       ParseError(const char* file, int line, const String& expression,
00419           const String& message)
00420         ;
00421     };
00422 
00426     class BALL_EXPORT Precondition
00427       : public GeneralException
00428     {
00429       public:
00431       Precondition(const char* file, int line, const char* condition) ;
00432     };
00433 
00437     class BALL_EXPORT Postcondition
00438       : public GeneralException
00439     {
00440       public:
00442       Postcondition(const char* file, int line, const char* condition) ;
00443     };
00444 
00446     class BALL_EXPORT InvalidOption: public Exception::GeneralException
00447     {
00448       public:
00449 
00451         InvalidOption(const char* file, int line, String option)
00452           ;
00453     };
00454     
00456     class BALL_EXPORT TooManyErrors
00457       : public Exception::GeneralException
00458     {
00459       public:
00461       TooManyErrors(const char* file, int line) ;
00462     };
00463      
00465     class BALL_EXPORT TooManyBonds
00466       : public Exception::GeneralException
00467     {
00468       public:
00470       TooManyBonds(const char* file, int line, const String& error) ;
00471     };
00472     
00476     class BALL_EXPORT CUDAError 
00477       : public Exception::GeneralException
00478     {
00479       public:
00480       CUDAError(const char* file, int line, const String& error) ;                  
00481     };
00482 
00490     class BALL_EXPORT NoBufferAvailable 
00491       : public Exception::GeneralException
00492     {
00493     public:
00494       NoBufferAvailable(const char* file, int line, const String& reason) ;
00495     };
00496 
00502     class BALL_EXPORT FormatUnsupported
00503       : public Exception::GeneralException
00504     {
00505     public:
00506       FormatUnsupported(const char* file, int line) ;
00507     };
00508 
00511     class BALL_EXPORT GlobalExceptionHandler
00512     {
00513       public:
00517 
00534       GlobalExceptionHandler() ;
00536       
00540         
00542       static void setName(const String& name) ;
00543         
00545       static void setMessage(const String& message) ;
00546 
00548       static void setLine(int line) ;
00549 
00551       static void setFile(const String& file) ;
00552 
00554       static void set
00555         (const String& file, int line, 
00556          const String& name, const String& message)
00557         ;
00559       
00560       protected:
00561 
00563       static void terminate() ;
00564 
00566       static void newHandler() throw(Exception::OutOfMemory);
00567 
00568       static std::string file_;
00569       static int         line_;
00570       static std::string name_;
00571       static std::string message_;
00572     };
00573 
00576     BALL_EXPORT extern GlobalExceptionHandler globalHandler;
00577 
00578   }
00597     BALL_EXPORT
00598     std::ostream& operator << (std::ostream& os, const Exception::GeneralException& e);
00599   
00600 } // namespace BALL
00601 
00602 #endif // BALL_COMMON_EXCEPTION_H