10 #include "MEDMEM_Exception.hxx"
20 const char* duplicate( const char *const str ) ;
22 const char* duplicate( const char *const str )
25 const size_t length = strlen( str ) ;
27 char *new_str = new char[ 1+length ] ;
29 strcpy( new_str , str ) ;
33 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
35 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
40 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
45 const size_t l1 = strlen(text) ;
47 const char* prefix = "MED Exception" ;
48 const size_t l0 = strlen(prefix) ;
52 const size_t l2 = strlen(fileName) ;
54 ASSERT(lineNumber>=1) ;
55 const size_t l3 = 1+int(log10(float(lineNumber))) ;
57 const size_t l4 = l0+l1+l2+l3+10+1 ;
58 newText = new char [ l4 ] ;
59 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
60 ASSERT(newText[l4-1] == '\0' );
65 newText = new char [ l0+l1+3+1 ] ;
66 sprintf( newText , "%s : %s" , prefix, text ) ;
73 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) )
79 MEDEXCEPTION::~MEDEXCEPTION() throw ()
84 char *& txt = (char*)_text ;
92 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
98 ostream & operator<<( ostream &os , const MEDEXCEPTION &ex )
106 const char* MEDEXCEPTION::what( void ) const throw ()
112 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
115 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
118 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
120 const char *text, const char *fileName/*=0*/,
121 const unsigned int lineNumber/*=0*/
122 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
124 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};