~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/Exception.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Exception.h>
 
2
 
 
3
 
 
4
CPPUNIT_NS_BEGIN
 
5
 
 
6
 
 
7
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
 
8
/*!
 
9
 * \deprecated Use SourceLine::isValid() instead.
 
10
 */
 
11
const std::string Exception::UNKNOWNFILENAME = "<unknown>";
 
12
 
 
13
/*!
 
14
 * \deprecated Use SourceLine::isValid() instead.
 
15
 */
 
16
const long Exception::UNKNOWNLINENUMBER = -1;
 
17
#endif
 
18
 
 
19
 
 
20
Exception::Exception( const Exception &other )
 
21
   : std::exception( other )
 
22
 
23
  m_message = other.m_message; 
 
24
  m_sourceLine = other.m_sourceLine;
 
25
 
26
 
 
27
 
 
28
Exception::Exception( const Message &message, 
 
29
                      const SourceLine &sourceLine )
 
30
    : m_message( message )
 
31
    , m_sourceLine( sourceLine )
 
32
{
 
33
}
 
34
 
 
35
 
 
36
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
 
37
Exception::Exception( std::string message, 
 
38
                      long lineNumber, 
 
39
                      std::string fileName )
 
40
    : m_message( message )
 
41
    , m_sourceLine( fileName, lineNumber )
 
42
{
 
43
}
 
44
#endif
 
45
 
 
46
 
 
47
Exception::~Exception() throw()
 
48
{
 
49
}
 
50
 
 
51
 
 
52
Exception & 
 
53
Exception::operator =( const Exception& other )
 
54
 
55
// Don't call superclass operator =(). VC++ STL implementation
 
56
// has a bug. It calls the destructor and copy constructor of 
 
57
// std::exception() which reset the virtual table to std::exception.
 
58
//  SuperClass::operator =(other);
 
59
 
 
60
  if ( &other != this )
 
61
  {
 
62
    m_message = other.m_message; 
 
63
    m_sourceLine = other.m_sourceLine;
 
64
  }
 
65
 
 
66
  return *this; 
 
67
}
 
68
 
 
69
 
 
70
const char*
 
71
Exception::what() const throw()
 
72
{
 
73
  Exception *mutableThis = CPPUNIT_CONST_CAST( Exception *, this );
 
74
  mutableThis->m_whatMessage = m_message.shortDescription() + "\n" + 
 
75
                               m_message.details();
 
76
  return m_whatMessage.c_str();
 
77
}
 
78
 
 
79
 
 
80
SourceLine 
 
81
Exception::sourceLine() const
 
82
{
 
83
  return m_sourceLine;
 
84
}
 
85
 
 
86
 
 
87
Message 
 
88
Exception::message() const
 
89
{
 
90
  return m_message;
 
91
}
 
92
 
 
93
 
 
94
void 
 
95
Exception::setMessage( const Message &message )
 
96
{
 
97
  m_message = message;
 
98
}
 
99
 
 
100
 
 
101
#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED
 
102
long 
 
103
Exception::lineNumber() const
 
104
 
105
  return m_sourceLine.isValid() ? m_sourceLine.lineNumber() : 
 
106
                                  UNKNOWNLINENUMBER; 
 
107
}
 
108
 
 
109
 
 
110
std::string 
 
111
Exception::fileName() const
 
112
 
113
  return m_sourceLine.isValid() ? m_sourceLine.fileName() : 
 
114
                                  UNKNOWNFILENAME;
 
115
}
 
116
#endif
 
117
 
 
118
 
 
119
Exception *
 
120
Exception::clone() const
 
121
{
 
122
  return new Exception( *this );
 
123
}
 
124
 
 
125
 
 
126
CPPUNIT_NS_END