Changeset 3585 in Sophya for trunk/SophyaLib/BaseTools/pexceptions.cc
- Timestamp:
- Mar 5, 2009, 2:24:17 PM (17 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.