10 #include "MEDMEM_Exception.hxx"
22 Function used to duplicate char *
24 const char* duplicate( const char *const str ) ;
25 const char* duplicate( const char *const str )
28 const size_t length = strlen( str ) ;
30 char *new_str = new char[ 1+length ] ;
32 strcpy( new_str , str ) ;
37 \internal Default Constructor (Should not be used)
39 // ------------------------------------------------------ //
40 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
41 // ------------------------------------------------------ //
43 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
50 Function used to elaborate the text of the MEDEXCEPTION
52 // --------------------------------------------------------------------------------------- //
53 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
54 // --------------------------------------------------------------------------------------- //
59 const size_t l1 = strlen(text) ;
61 const char* prefix = "MED Exception" ;
62 const size_t l0 = strlen(prefix) ;
66 const size_t l2 = strlen(fileName) ;
68 ASSERT(lineNumber>=1) ;
69 const size_t l3 = 1+int(log10(float(lineNumber))) ;
71 const size_t l4 = l0+l1+l2+l3+10+1 ;
72 newText = new char [ l4 ] ;
73 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
74 ASSERT(newText[l4-1] == '\0' );
79 newText = new char [ l0+l1+3+1 ] ;
80 sprintf( newText , "%s : %s" , prefix, text ) ;
88 It will create the text of the MEDEXCEPTION from the different parameters.
89 It will take the form : \n
90 MEDEXCEPTION, fileName, lineNumber and text of the exception
92 // ------------------------------------------------------------------------------------------------ //
93 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
94 exception(), _text( makeText( text , fileName , lineNumber ) )
95 // ------------------------------------------------------------------------------------------------ //
102 If necessary desallocates Memory
105 // ------------------------------------//
106 MEDEXCEPTION::~MEDEXCEPTION() throw ()
107 // ------------------------------------//
112 char *& txt = (char*)_text ;
115 ASSERT(_text==NULL) ;
120 Copy Constructor : \n
121 Should not be used very often
123 // ----------------------------------------------------------------------- //
124 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
125 // ----------------------------------------------------------------------- //
130 Operator << : put the message to the given stream.
132 // ------------------------------------------------------- //
133 ostream & operator<<( ostream &os , const MEDEXCEPTION &ex )
134 // ------------------------------------------------------- //
141 Return a char * which contain the message.
143 // ------------------------------------------------- //
144 const char* MEDEXCEPTION::what( void ) const throw ()
145 // ------------------------------------------------- //
151 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
154 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
157 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
159 const char *text, const char *fileName/*=0*/,
160 const unsigned int lineNumber/*=0*/
161 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
163 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};