2 //=============================================================================
3 // File : Utils_SALOME_Exception.cxx
4 // Created : Mon Nov 5 17:01:47 CET 2001
5 // Author : Antoine YESSAYAN, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
13 #include "Utils_SALOME_Exception.hxx"
14 #include "utilities.h"
23 const char* duplicate( const char *const str ) ;
25 SALOME_Exception::SALOME_Exception( void ): exception() , _text(0)
27 MESSAGE( "You must user the standard builder : SALOME_Exception::SALOME_Exception( const char *text )" ) ;
33 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
38 const size_t l1 = 1+strlen(text) ;
41 const char* prefix = "Salome Exception" ;
42 const size_t l0 = 2+strlen(prefix) ;
46 const size_t l2 = 4+strlen(fileName) ;
49 ASSERT(lineNumber>=1) ;
50 const size_t l3 = 4+int(log10(float(lineNumber))) ;
52 newText = new char [ 1+l0+l1+l2+l3 ] ;
53 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
57 newText = new char [ 1+l0+l1 ] ;
58 sprintf( newText , "%s : %s" , prefix, text ) ;
65 SALOME_Exception::SALOME_Exception( const char *text, const char *fileName, const unsigned int lineNumber ) : exception(), _text( makeText( text , fileName , lineNumber ) )
70 SALOME_Exception::~SALOME_Exception() throw ()
75 char *& txt = (char*)_text ;
83 SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text))
89 ostream & operator<<( ostream &os , const SALOME_Exception &ex )
97 const char* SALOME_Exception::what( void ) const throw ()