10 #include "MEDMEM_Exception.hxx"
11 using namespace MEDMEM;
23 Function used to duplicate char *
25 const char* duplicate( const char *const str ) ;
26 const char* duplicate( const char *const str )
29 const size_t length = strlen( str ) ;
31 char *new_str = new char[ 1+length ] ;
33 strcpy( new_str , str ) ;
38 \internal Default Constructor (Should not be used)
40 // ------------------------------------------------------ //
41 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
42 // ------------------------------------------------------ //
44 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
51 Function used to elaborate the text of the MEDEXCEPTION
53 // --------------------------------------------------------------------------------------- //
54 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
55 // --------------------------------------------------------------------------------------- //
60 const size_t l1 = strlen(text) ;
62 const char* prefix = "MED Exception" ;
63 const size_t l0 = strlen(prefix) ;
67 const size_t l2 = strlen(fileName) ;
69 ASSERT(lineNumber>=1) ;
70 const size_t l3 = 1+int(log10(float(lineNumber))) ;
72 const size_t l4 = l0+l1+l2+l3+10+1 ;
73 newText = new char [ l4 ] ;
74 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
75 ASSERT(newText[l4-1] == '\0' );
80 newText = new char [ l0+l1+3+1 ] ;
81 sprintf( newText , "%s : %s" , prefix, text ) ;
89 It will create the text of the MEDEXCEPTION from the different parameters.
90 It will take the form : \n
91 MEDEXCEPTION, fileName, lineNumber and text of the exception
93 // ------------------------------------------------------------------------------------------------ //
94 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
95 exception(), _text( makeText( text , fileName , lineNumber ) )
96 // ------------------------------------------------------------------------------------------------ //
103 If necessary desallocates Memory
106 // ------------------------------------//
107 MEDEXCEPTION::~MEDEXCEPTION() throw ()
108 // ------------------------------------//
113 char *& txt = (char*)_text ;
116 ASSERT(_text==NULL) ;
121 Copy Constructor : \n
122 Should not be used very often
124 // ----------------------------------------------------------------------- //
125 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
126 // ----------------------------------------------------------------------- //
131 Operator << : put the message to the given stream.
133 // ------------------------------------------------------- //
134 ostream & MEDMEM::operator<<( ostream &os , const MEDEXCEPTION &ex )
135 // ------------------------------------------------------- //
142 Return a char * which contain the message.
144 // ------------------------------------------------- //
145 const char* MEDEXCEPTION::what( void ) const throw ()
146 // ------------------------------------------------- //
152 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
155 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
158 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
160 const char *text, const char *fileName/*=0*/,
161 const unsigned int lineNumber/*=0*/
162 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
164 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};