summaryrefslogtreecommitdiff
path: root/src/cppunit/Exception.cpp
blob: 26a805ec21e0d3b9607d7f48ffd6bb40fa2b5aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "cppunit/Exception.h"


namespace CppUnit {


const std::string Exception::UNKNOWNFILENAME = "<unknown>";

const long Exception::UNKNOWNLINENUMBER = -1;


/// Construct the exception
Exception::Exception (const Exception& other) : exception (other)
{ 
  m_message       = other.m_message; 
  m_lineNumber    = other.m_lineNumber;
  m_fileName      = other.m_fileName;
} 


Exception::Exception( std::string message, 
                      long lineNumber, 
                      std::string fileName ) : 
    m_message( message ), 
    m_lineNumber( lineNumber ), 
    m_fileName( fileName )
{
}


/// Destruct the exception
Exception::~Exception ()
{
}


/// Perform an assignment
Exception& 
Exception::operator=( const Exception& other )
{ 
  exception::operator= (other);

  if (&other != this) 
  {
    m_message       = other.m_message; 
    m_lineNumber    = other.m_lineNumber;
    m_fileName      = other.m_fileName;
  }

  return *this; 
}


/// Return descriptive message
const char*
Exception::what() const throw ()
{ 
  return m_message.c_str (); 
}


/// The line on which the error occurred
long 
Exception::lineNumber()
{ 
  return m_lineNumber; 
}


/// The file in which the error occurred
std::string 
Exception::fileName()
{ 
  return m_fileName; 
}


Exception *
Exception::clone() const
{
  return new Exception( *this );
}


bool 
Exception::isInstanceOf( const Type &exceptionType ) const
{
  return exceptionType == type();
}


Exception::Type
Exception::type()
{
  return Type( "CppUnit::Exception" );
}


}  // namespace CppUnit