9 #include "MEDMEM_Exception.hxx"
19 const char* duplicate( const char *const str ) ;
21 const char* duplicate( const char *const str )
24 const size_t length = strlen( str ) ;
26 char *new_str = new char[ 1+length ] ;
28 strcpy( new_str , str ) ;
32 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
34 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
39 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
44 const size_t l1 = 1+strlen(text) ;
47 const char* prefix = "MED Exception" ;
48 const size_t l0 = 2+strlen(prefix) ;
52 const size_t l2 = 4+strlen(fileName) ;
55 ASSERT(lineNumber>=1) ;
56 const size_t l3 = 4+int(log10(float(lineNumber))) ;
58 newText = new char [ 1+l0+l1+l2+l3 ] ;
59 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
63 newText = new char [ 1+l0+l1 ] ;
64 sprintf( newText , "%s : %s" , prefix, text ) ;
71 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) )
77 MEDEXCEPTION::~MEDEXCEPTION() throw ()
82 char *& txt = (char*)_text ;
90 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
96 ostream & operator<<( ostream &os , const MEDEXCEPTION &ex )
104 const char* MEDEXCEPTION::what( void ) const throw ()
110 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
113 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
116 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
118 const char *text, const char *fileName=0,
119 const unsigned int lineNumber=0
120 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
122 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};