1#include "cppunit/Exception.h"
2
3
4namespace CppUnit {
5
6
7#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
8/*!
9 * \deprecated Use SourceLine::isValid() instead.
10 */
11const string Exception::UNKNOWNFILENAME = "<unknown>";
12
13/*!
14 * \deprecated Use SourceLine::isValid() instead.
15 */
16const long Exception::UNKNOWNLINENUMBER = -1;
17#endif
18
19
20/// Construct the exception
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 */
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 */
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
55Exception::~Exception () throw()
56{
57}
58
59
60/// Perform an assignment
61Exception&
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
80const char*
81Exception::what() const throw()
82{
83  return m_message.c_str ();
84}
85
86/// Location where the error occured
87SourceLine
88Exception::sourceLine() const
89{
90  return m_sourceLine;
91}
92
93
94#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
95/// The line on which the error occurred
96long
97Exception::lineNumber() const
98{
99  return m_sourceLine.isValid() ? m_sourceLine.lineNumber() :
100                                  UNKNOWNLINENUMBER;
101}
102
103
104/// The file in which the error occurred
105string
106Exception::fileName() const
107{
108  return m_sourceLine.isValid() ? m_sourceLine.fileName() :
109                                  UNKNOWNFILENAME;
110}
111#endif
112
113
114Exception *
115Exception::clone() const
116{
117  return new Exception( *this );
118}
119
120
121bool
122Exception::isInstanceOf( const Type &exceptionType ) const
123{
124  return exceptionType == type();
125}
126
127
128Exception::Type
129Exception::type()
130{
131  return Type( "CppUnit::Exception" );
132}
133
134
135}  // namespace CppUnit
136