Ignore:
Timestamp:
Mar 5, 2009, 2:24:17 PM (17 years ago)
Author:
ansari
Message:

Ajout heritage exceptions SOPHYA de std::exception (+method what()) - nettoyage/suppression TRY/CATCH... , Reza 05/03/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/pexceptions.h

    r2505 r3585  
    1010// Petit utilitaire pour accoler numero de ligne et nom de fichier aux messages
    1111// d'exception
     12//! Utiliy macro to append file name and line number to a const char* string 
    1213#define PExcLongMessage(a) BuildLongExceptionMessage(a,__FILE__,__LINE__)
    1314
     15#define SEXC_MAXMSGLEN 160
    1416namespace SOPHYA {
    1517
     
    1719  string BuildLongExceptionMessage(const char * s, const char *file, int line);
    1820
    19 /*! \ingroup BaseTools
    20     \brief Base exception class in Sophya
    21 
    22     Ancestor for PError and PException
    23     It has a message, and an id to give more
    24     information on the exception.
    25 */
    26   class PThrowable {
     21  class PThrowable : public std::exception {
    2722  public:
    2823    //! Constructor with the message and error-id (optional) specification
    29     explicit PThrowable(const string& m, int ident=0)
    30       : msg(m), id(ident) {}
    31     explicit PThrowable(const char* m, int ident=0)
    32       : msg(m), id(ident) {}
    33     virtual ~PThrowable() { }
     24    explicit PThrowable(const string& m, int ident=0) throw() ;
     25    explicit PThrowable(const char* m, int ident=0) throw() ;
     26    virtual ~PThrowable() throw();
     27    //! Implementation of std::exception what() method, returning the exception message
     28    virtual const char* what() const throw();
    3429    //! Returns the associated message string
    35     virtual string const& Msg() const  {return msg;}
     30    virtual string const Msg() const;
    3631    //! Returns the associated error-id
    37     virtual int Id() const {return id; }
     32    virtual int Id() const;
    3833  private:
    39     string msg;
    40     int    id;
     34    char msg_[SEXC_MAXMSGLEN];
     35    int    id_;
    4136  };
    4237
     
    4944  class PError : public PThrowable {
    5045  public:
    51     explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
    52     explicit PError(const char* m, int id=0) : PThrowable(m,id) {}
     46    explicit PError(const string& m, int id=0) throw() : PThrowable(m,id) {}
     47    explicit PError(const char* m, int id=0) throw() : PThrowable(m,id) {}
    5348  };
    5449 
     
    5752  class PException : public PThrowable {
    5853  public:
    59     explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
     54    explicit PException(const string& m, int id=0) throw() : PThrowable(m,id) {}
     55    explicit PException(const char* m, int id=0) throw() : PThrowable(m,id) {}
    6056  };
    6157 
     
    7167  class AllocationError : public PError {
    7268  public:
    73     explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
    74     explicit AllocationError(const char* m, int id=0) : PError(m,id) {}
     69    explicit AllocationError(const string& m, int id=0) throw() : PError(m,id) {}
     70    explicit AllocationError(const char* m, int id=0) throw() : PError(m,id) {}
    7571  };
    7672 
     
    7975  class NullPtrError : public PError {
    8076  public:
    81     explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
    82     explicit NullPtrError(const char* m, int id=0) : PError(m,id) {}
     77    explicit NullPtrError(const string& m, int id=0) throw() : PError(m,id) {}
     78    explicit NullPtrError(const char* m, int id=0) throw() : PError(m,id) {}
    8379  };
    8480 
     
    8884  class ForbiddenError : public PError {
    8985  public:
    90     explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
    91     explicit ForbiddenError(const char* m, int id=0) : PError(m,id) {}
     86    explicit ForbiddenError(const string& m, int id=0) throw() : PError(m,id) {}
     87    explicit ForbiddenError(const char* m, int id=0) throw() : PError(m,id) {}
    9288  };
    9389
     
    9793  class AssertionFailedError : public PError {
    9894  public:
    99     explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
    100     explicit AssertionFailedError(const char* m, int id=0) : PError(m,id) {}
     95    explicit AssertionFailedError(const string& m, int id=0) throw() : PError(m,id) {}
     96    explicit AssertionFailedError(const char* m, int id=0) throw() : PError(m,id) {}
    10197  };
    10298 
     
    120116  class IOExc : public PException {
    121117  public:
    122     explicit IOExc(const string& m, int id=0) : PException(m,id) {}
    123     explicit IOExc(const char* m, int id=0) : PException(m,id) {}
     118    explicit IOExc(const string& m, int id=0) throw() : PException(m,id) {}
     119    explicit IOExc(const char* m, int id=0) throw() : PException(m,id) {}
    124120  };
    125121
     
    128124  class FileFormatExc : public IOExc {
    129125  public:
    130     explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {}
    131     explicit FileFormatExc(const char* m, int id=0) : IOExc(m,id) {}
     126    explicit FileFormatExc(const string& m, int id=0) throw() : IOExc(m,id) {}
     127    explicit FileFormatExc(const char* m, int id=0) throw() : IOExc(m,id) {}
    132128  };
    133129
     
    136132  class SzMismatchError : public PException {
    137133  public:
    138     explicit SzMismatchError(const string& m, int id=0) : PException(m,id) {}
    139     explicit SzMismatchError(const char* m, int id=0) : PException(m,id) {}
     134    explicit SzMismatchError(const string& m, int id=0) throw() : PException(m,id) {}
     135    explicit SzMismatchError(const char* m, int id=0) throw() : PException(m,id) {}
    140136  };
    141137 
     
    144140  class RangeCheckError : public PException {
    145141  public:
    146     explicit RangeCheckError(const string& m, int id=0) : PException(m,id) {}
    147     explicit RangeCheckError(const char* m, int id=0) : PException(m,id) {}
     142    explicit RangeCheckError(const string& m, int id=0) throw() : PException(m,id) {}
     143    explicit RangeCheckError(const char* m, int id=0) throw() : PException(m,id) {}
    148144  };
    149145 
     
    152148  class ParmError : public PException {
    153149  public:
    154     explicit ParmError(const string& m, int id=0) : PException(m,id) {}
    155     explicit ParmError(const char* m, int id=0) : PException(m,id) {}
     150    explicit ParmError(const string& m, int id=0) throw() : PException(m,id) {}
     151    explicit ParmError(const char* m, int id=0) throw() : PException(m,id) {}
    156152  };
    157153
     
    160156  class NotAvailableOperation : public PException {
    161157  public:
    162     explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {}
    163     explicit NotAvailableOperation(const char* m, int id=0) : PException(m,id) {}
     158    explicit NotAvailableOperation(const string& m, int id=0) throw() : PException(m,id) {}
     159    explicit NotAvailableOperation(const char* m, int id=0) throw() : PException(m,id) {}
    164160  };
    165161
     
    168164  class TypeMismatchExc : public PException {
    169165  public:
    170     explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
    171     explicit TypeMismatchExc(const char* m, int id=0) : PException(m,id) {}
     166    explicit TypeMismatchExc(const string& m, int id=0) throw() : PException(m,id) {}
     167    explicit TypeMismatchExc(const char* m, int id=0) throw() : PException(m,id) {}
    172168  };
    173169
     
    176172  class MathExc : public PException {
    177173  public:
    178     explicit MathExc(const string& m, int id=0) : PException(m,id) {}
    179     explicit MathExc(const char* m, int id=0) : PException(m,id) {}
     174    explicit MathExc(const string& m, int id=0) throw() : PException(m,id) {}
     175    explicit MathExc(const char* m, int id=0) throw() : PException(m,id) {}
    180176  };
    181177 
     
    184180  class SingMatrixExc : public MathExc {
    185181  public:
    186     explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
    187     explicit SingMatrixExc(const char* m, int id=0) : MathExc(m,id) {}
     182    explicit SingMatrixExc(const string& m, int id=0) throw() : MathExc(m,id) {}
     183    explicit SingMatrixExc(const char* m, int id=0) throw() : MathExc(m,id) {}
    188184  };
    189185
     
    192188  class DuplicateIdExc : public PException {
    193189  public:
    194     explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
    195     explicit DuplicateIdExc(const char* m, int id=0) : PException(m,id) {}
     190    explicit DuplicateIdExc(const string& m, int id=0) throw() : PException(m,id) {}
     191    explicit DuplicateIdExc(const char* m, int id=0) throw() : PException(m,id) {}
    196192  };
    197193 
     
    200196  class NotFoundExc : public PException {
    201197  public:
    202     explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
    203     explicit NotFoundExc(const char* m, int id=0) : PException(m,id) {}
     198    explicit NotFoundExc(const string& m, int id=0) throw() : PException(m,id) {}
     199    explicit NotFoundExc(const char* m, int id=0) throw() : PException(m,id) {}
    204200  };
    205201 
     
    208204  class CaughtSignalExc : public PException {
    209205  public:
    210     explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
    211     explicit CaughtSignalExc(const char* m, int id=0) : PException(m,id) {}
     206    explicit CaughtSignalExc(const string& m, int id=0) throw() : PException(m,id) {}
     207    explicit CaughtSignalExc(const char* m, int id=0) throw() : PException(m,id) {}
    212208 };
    213209   
     
    223219       {if (!(_x_)) throw(NullPtrError(#_x_))}
    224220
    225 void InitFailNewHandler();
    226  
     221
    227222     
    228 // Compatibility with EROS-PEIDA exceptions
    229 
    230 
    231 #define TRY try
    232 #define CATCH(_var) catch(long _var)
    233 #define CATCHALL catch(...)
    234 #define ENDTRY
    235 
    236 #define THROW(_i) throw( _i);
    237 
    238 #define THROW_ THROW(0)
    239 
    240 #define THROW_SAME throw;
    241 
    242 
    243 #define DBASSERT(_x_) ASSERT(_x_)
    244 
    245223#endif
Note: See TracChangeset for help on using the changeset viewer.