Changeset 3585 in Sophya
- Timestamp:
- Mar 5, 2009, 2:24:17 PM (17 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/pexceptions.cc
r2615 r3585 3 3 #include <iostream> 4 4 #include <stdio.h> 5 #include <string.h> 5 6 6 void PFailHandler(void); 7 7 /* --- Nettoyage par Reza, Mars 2009 8 8 // egcs ne semble pas connaitre set_new_handler (Reza 26/04/99) 9 9 // ca ne passe plus avec SGI-CC -LANG:std $CHECK$ Reza 14/02/2003 10 #if defined( __GNUG__ ) || defined(__SGICC__)11 void PFailHandler(void) {}12 void InitFailNewHandler() {}13 #else14 15 10 void PFailHandler(void) 16 11 { … … 19 14 throw(AllocationError("new")); 20 15 } 21 22 16 void InitFailNewHandler() 23 17 { 24 18 set_new_handler(PFailHandler); 25 19 } 26 #endif 20 --- FIN nettoyage */ 27 21 28 string SOPHYA::BuildLongExceptionMessage(const char * s, const char *file, int line) 22 23 namespace SOPHYA { 24 25 /*! 26 \ingroup BaseTools 27 \brief Utility function for appending a file name and line number to a message 28 29 In practice, the macro \b PExcLongMessage(a) can be used to append file name 30 and line number to the message a. 31 */ 32 33 string BuildLongExceptionMessage(const char * s, const char *file, int line) 29 34 { 30 35 char buff[32]; … … 34 39 return(rs); 35 40 } 41 42 /*! 43 \class PThrowable 44 \ingroup BaseTools 45 \brief Base exception class in Sophya, inherits from std::exception 46 47 This class is the ancestor class for PError and PException classes which are 48 the base classes for all exceptions used in SOPHYA. The PThrowable class inherits 49 from the standard c++ exception base class, std::exception and implements the what() 50 method. A message (string/char*) passed to the constructor is kept in the exception object, 51 and can be retrieved using the \b what() method or \b Msg() method. An integer identifier 52 can also be associated with the exception objet and retrieved by \b Id(). 53 The message passed to the constructor is truncated to a maximum length defined by 54 SEXC_MAXMSGLEN (=160 characters). 55 */ 56 57 PThrowable::PThrowable(const string& m, int ident) throw() 58 { 59 id_ = ident; 60 strncpy(msg_, m.c_str(), SEXC_MAXMSGLEN-1); 61 msg_[SEXC_MAXMSGLEN-1] = '\0'; 62 } 63 64 PThrowable::PThrowable(const char* m, int ident) throw() 65 { 66 id_ = ident; 67 if (m!=NULL) { 68 strncpy(msg_, m, SEXC_MAXMSGLEN-1); 69 msg_[SEXC_MAXMSGLEN-1] = '\0'; 70 } 71 else msg_[0] = '\0'; 72 } 73 74 PThrowable::~PThrowable() throw() 75 { 76 } 77 const char* PThrowable::what() const throw() 78 { 79 return msg_; 80 } 81 82 string const PThrowable::Msg() const 83 { 84 return (string(msg_)); 85 } 86 87 int PThrowable::Id() const 88 { 89 return id_; 90 } 91 92 } // namespace SOPHYA -
trunk/SophyaLib/BaseTools/pexceptions.h
r2505 r3585 10 10 // Petit utilitaire pour accoler numero de ligne et nom de fichier aux messages 11 11 // d'exception 12 //! Utiliy macro to append file name and line number to a const char* string 12 13 #define PExcLongMessage(a) BuildLongExceptionMessage(a,__FILE__,__LINE__) 13 14 15 #define SEXC_MAXMSGLEN 160 14 16 namespace SOPHYA { 15 17 … … 17 19 string BuildLongExceptionMessage(const char * s, const char *file, int line); 18 20 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 { 27 22 public: 28 23 //! 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(); 34 29 //! Returns the associated message string 35 virtual string const & Msg() const {return msg;}30 virtual string const Msg() const; 36 31 //! Returns the associated error-id 37 virtual int Id() const {return id; }32 virtual int Id() const; 38 33 private: 39 string msg;40 int id ;34 char msg_[SEXC_MAXMSGLEN]; 35 int id_; 41 36 }; 42 37 … … 49 44 class PError : public PThrowable { 50 45 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) {} 53 48 }; 54 49 … … 57 52 class PException : public PThrowable { 58 53 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) {} 60 56 }; 61 57 … … 71 67 class AllocationError : public PError { 72 68 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) {} 75 71 }; 76 72 … … 79 75 class NullPtrError : public PError { 80 76 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) {} 83 79 }; 84 80 … … 88 84 class ForbiddenError : public PError { 89 85 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) {} 92 88 }; 93 89 … … 97 93 class AssertionFailedError : public PError { 98 94 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) {} 101 97 }; 102 98 … … 120 116 class IOExc : public PException { 121 117 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) {} 124 120 }; 125 121 … … 128 124 class FileFormatExc : public IOExc { 129 125 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) {} 132 128 }; 133 129 … … 136 132 class SzMismatchError : public PException { 137 133 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) {} 140 136 }; 141 137 … … 144 140 class RangeCheckError : public PException { 145 141 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) {} 148 144 }; 149 145 … … 152 148 class ParmError : public PException { 153 149 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) {} 156 152 }; 157 153 … … 160 156 class NotAvailableOperation : public PException { 161 157 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) {} 164 160 }; 165 161 … … 168 164 class TypeMismatchExc : public PException { 169 165 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) {} 172 168 }; 173 169 … … 176 172 class MathExc : public PException { 177 173 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) {} 180 176 }; 181 177 … … 184 180 class SingMatrixExc : public MathExc { 185 181 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) {} 188 184 }; 189 185 … … 192 188 class DuplicateIdExc : public PException { 193 189 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) {} 196 192 }; 197 193 … … 200 196 class NotFoundExc : public PException { 201 197 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) {} 204 200 }; 205 201 … … 208 204 class CaughtSignalExc : public PException { 209 205 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) {} 212 208 }; 213 209 … … 223 219 {if (!(_x_)) throw(NullPtrError(#_x_))} 224 220 225 void InitFailNewHandler(); 226 221 227 222 228 // Compatibility with EROS-PEIDA exceptions229 230 231 #define TRY try232 #define CATCH(_var) catch(long _var)233 #define CATCHALL catch(...)234 #define ENDTRY235 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 245 223 #endif -
trunk/SophyaLib/BaseTools/sophyainit.cc
r3572 r3585 61 61 if (FgInit > 1) return; 62 62 63 InitFailNewHandler();64 63 ModListP = new map<string, double>; 65 64
Note:
See TracChangeset
for help on using the changeset viewer.