1 #include "cppunit/Exception.h" 2 3 4 namespace CppUnit { 5 6 7 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 8 /*! 9 * \deprecated Use SourceLine::isValid() instead. 10 */ 11 const string Exception::UNKNOWNFILENAME = "<unknown>"; 12 13 /*! 14 * \deprecated Use SourceLine::isValid() instead. 15 */ 16 const long Exception::UNKNOWNLINENUMBER = -1; 17 #endif 18 19 20 /// Construct the exception Exception(const Exception & other)21Exception::Exception( const Exception &other ) : 22 exception( other ) 23 { 24 m_message = other.m_message; 25 m_sourceLine = other.m_sourceLine; 26 } 27 28 29 /*! 30 * \deprecated Use other constructor instead. 31 */ Exception(std::string message,SourceLine sourceLine)32Exception::Exception( std::string message, 33 SourceLine sourceLine ) : 34 m_message( message ), 35 m_sourceLine( sourceLine ) 36 { 37 } 38 39 40 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 41 /*! 42 * \deprecated Use other constructor instead. 43 */ Exception(std::string message,long lineNumber,std::string fileName)44Exception::Exception( std::string message, 45 long lineNumber, 46 std::string fileName ) : 47 m_message( message ), 48 m_sourceLine( fileName, lineNumber ) 49 { 50 } 51 #endif 52 53 54 /// Destruct the exception ~Exception()55Exception::~Exception () throw() 56 { 57 } 58 59 60 /// Perform an assignment 61 Exception& operator =(const Exception & other)62Exception::operator =( const Exception& other ) 63 { 64 // Don't call superclass operator =(). VC++ STL implementation 65 // has a bug. It calls the destructor and copy constructor of 66 // exception() which reset the virtual table to exception. 67 // SuperClass::operator =(other); 68 69 if ( &other != this ) 70 { 71 m_message = other.m_message; 72 m_sourceLine = other.m_sourceLine; 73 } 74 75 return *this; 76 } 77 78 79 /// Return descriptive message 80 const char* what() const81Exception::what() const throw() 82 { 83 return m_message.c_str (); 84 } 85 86 /// Location where the error occured 87 SourceLine sourceLine() const88Exception::sourceLine() const 89 { 90 return m_sourceLine; 91 } 92 93 94 #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED 95 /// The line on which the error occurred 96 long lineNumber() const97Exception::lineNumber() const 98 { 99 return m_sourceLine.isValid() ? m_sourceLine.lineNumber() : 100 UNKNOWNLINENUMBER; 101 } 102 103 104 /// The file in which the error occurred 105 string fileName() const106Exception::fileName() const 107 { 108 return m_sourceLine.isValid() ? m_sourceLine.fileName() : 109 UNKNOWNFILENAME; 110 } 111 #endif 112 113 114 Exception * clone() const115Exception::clone() const 116 { 117 return new Exception( *this ); 118 } 119 120 121 bool isInstanceOf(const Type & exceptionType) const122Exception::isInstanceOf( const Type &exceptionType ) const 123 { 124 return exceptionType == type(); 125 } 126 127 128 Exception::Type type()129Exception::type() 130 { 131 return Type( "CppUnit::Exception" ); 132 } 133 134 135 } // namespace CppUnit 136