/[escript]/trunk/tools/CppUnitTest/inc/CppUnitTest/CppUnitException.h
ViewVC logotype

Contents of /trunk/tools/CppUnitTest/inc/CppUnitTest/CppUnitException.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (17 years, 4 months ago) by jgs
File MIME type: text/plain
File size: 2837 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

1
2 #ifndef CPPUNIT_CPPUNITEXCEPTION_H
3 #define CPPUNIT_CPPUNITEXCEPTION_H
4
5 /*
6 * CppUnitException is an exception that serves
7 * descriptive strings through its what () method
8 *
9 */
10
11 #include <exception>
12 #include <string>
13
14 #include "CppUnitTest/CppUnitTestNamespace.h"
15 BEGIN_NAMESPACE_CPPUNITTEST
16
17 #define CPPUNIT_UNKNOWNFILENAME "<unknown>"
18 #define CPPUNIT_UNKNOWNLINENUMBER (-1)
19
20 //#if defined (__sgi) && ( _COMPILER_VERSION < 730 )
21 //class exception {
22 // public:
23 // virtual ~exception() {}
24 // virtual const char* what() const throw() { return ""; }
25 //};
26 //#endif
27
28 class CppUnitException : public std::exception
29 {
30 public:
31 CppUnitException (std::string message = "",
32 long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,
33 std::string fileName = CPPUNIT_UNKNOWNFILENAME);
34 CppUnitException (const CppUnitException& other);
35
36 virtual ~CppUnitException () throw() ;
37
38 CppUnitException& operator= (const CppUnitException& other);
39
40 const char *what() const throw ();
41
42 long lineNumber ();
43 std::string fileName ();
44
45 private:
46 std::string m_message;
47 long m_lineNumber;
48 std::string m_fileName;
49
50 };
51
52
53 // Construct the exception
54 inline CppUnitException::CppUnitException (const CppUnitException& other)
55 : std::exception (other)
56 {
57 m_message = other.m_message;
58 m_lineNumber = other.m_lineNumber;
59 m_fileName = other.m_fileName;
60 }
61
62 inline CppUnitException::CppUnitException (std::string message, long lineNumber, std::string fileName)
63 : m_message (message), m_lineNumber (lineNumber), m_fileName (fileName)
64 {}
65
66
67 // Destruct the exception
68 inline CppUnitException::~CppUnitException () throw()
69 {}
70
71
72 // Perform an assignment
73 inline CppUnitException& CppUnitException::operator= (const CppUnitException& other)
74 {
75 #if defined MSWIN
76 //
77 // ms visual c++ compiler doesn't like the std::exception::operator=
78 // approach and the SG 7.2.1 compiler doesn't accept the this->exception
79 // style
80 //
81 this->exception::operator= (other);
82 #else
83 std::exception::operator= (other);
84 #endif
85
86 if (&other != this) {
87 m_message = other.m_message;
88 m_lineNumber = other.m_lineNumber;
89 m_fileName = other.m_fileName;
90 }
91
92 return *this;
93 }
94
95
96 // Return descriptive message
97 inline const char *CppUnitException::what() const throw ()
98 { return m_message.c_str (); }
99
100 // The line on which the error occurred
101 inline long CppUnitException::lineNumber ()
102 { return m_lineNumber; }
103
104
105 // The file in which the error occurred
106 inline std::string CppUnitException::fileName ()
107 { return m_fileName; }
108
109 END_NAMESPACE_CPPUNITTEST
110
111 #endif
112
113
114
115
116

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26