7 #include "MEDMEM_Exception.hxx"
10 using namespace MEDMEM;
21 Function used to duplicate char *
23 char* duplicate( const char *const str ) ;
24 char* duplicate( const char *const str )
27 const size_t length = strlen( str ) ;
29 char *new_str = new char[ 1+length ] ;
31 strcpy( new_str , str ) ;
36 \internal Default Constructor (Should not be used)
38 // ------------------------------------------------------ //
39 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
40 // ------------------------------------------------------ //
42 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
49 Function used to elaborate the text of the MEDEXCEPTION
51 // --------------------------------------------------------------------------------------- //
52 char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
53 // --------------------------------------------------------------------------------------- //
58 const size_t l1 = strlen(text) ;
60 const char* prefix = "MED Exception" ;
61 const size_t l0 = strlen(prefix) ;
65 const size_t l2 = strlen(fileName) ;
67 ASSERT(lineNumber>=1) ;
68 const size_t l3 = 1+int(log10(float(lineNumber))) ;
70 const size_t l4 = l0+l1+l2+l3+10+1 ;
71 newText = new char [ l4 ] ;
72 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
73 ASSERT(newText[l4-1] == '\0' );
78 newText = new char [ l0+l1+3+1 ] ;
79 sprintf( newText , "%s : %s" , prefix, text ) ;
87 It will create the text of the MEDEXCEPTION from the different parameters.
88 It will take the form : \n
89 MEDEXCEPTION, fileName, lineNumber and text of the exception
91 // ------------------------------------------------------------------------------------------------ //
92 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
93 exception(), _text( makeText( text , fileName , lineNumber ) )
94 // ------------------------------------------------------------------------------------------------ //
101 If necessary desallocates Memory
104 // ------------------------------------//
105 MEDEXCEPTION::~MEDEXCEPTION() throw ()
106 // ------------------------------------//
113 ASSERT(_text==NULL) ;
118 Copy Constructor : \n
119 Should not be used very often
121 // ----------------------------------------------------------------------- //
122 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
123 // ----------------------------------------------------------------------- //
128 Operator << : put the message to the given stream.
130 // ------------------------------------------------------- //
131 ostream & MEDMEM::operator<<( ostream &os , const MEDEXCEPTION &ex )
132 // ------------------------------------------------------- //
139 Return a char * which contain the message.
141 // ------------------------------------------------- //
142 const char* MEDEXCEPTION::what( void ) const throw ()
143 // ------------------------------------------------- //
149 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
152 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
155 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
157 const char *text, const char *fileName/*=0*/,
158 const unsigned int lineNumber/*=0*/
159 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
161 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};