1//
2// CppUnitException.h
3//
4
5
6#ifndef Poco_CppUnit_CppUnitException_INCLUDED
7#define Poco_CppUnit_CppUnitException_INCLUDED
8
9
10#include "Poco/CppUnit/CppUnit.h"
11#include <exception>
12#include <string>
13
14
15namespace CppUnit {
16
17
18class CppUnit_API CppUnitException: public std::exception
19 /// CppUnitException is an exception that serves
20 /// descriptive strings through its what() method
21{
22public:
23 CppUnitException(const std::string& message = "",
24 long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,
25 const std::string& fileName = CPPUNIT_UNKNOWNFILENAME);
26 CppUnitException(const std::string& message,
27 long lineNumber,
28 long data1lineNumber,
29 const std::string& fileName);
30 CppUnitException(const std::string& message,
31 long lineNumber,
32 long data1lineNumber,
33 long data2lineNumber,
34 const std::string& fileName);
35 CppUnitException(const CppUnitException& other);
36 virtual ~CppUnitException() throw();
37
38 CppUnitException& operator = (const CppUnitException& other);
39
40 const char* what() const throw ();
41
42 long lineNumber() const;
43 long data1LineNumber() const;
44 long data2LineNumber() const;
45 const std::string& fileName() const;
46
47 static const std::string CPPUNIT_UNKNOWNFILENAME;
48 static const int CPPUNIT_UNKNOWNLINENUMBER;
49
50private:
51 std::string _message;
52 long _lineNumber;
53 long _data1lineNumber;
54 long _data2lineNumber;
55 std::string _fileName;
56};
57
58
59inline CppUnitException::CppUnitException(const CppUnitException& other): exception (other)
60{
61 _message = other._message;
62 _lineNumber = other._lineNumber;
63 _data1lineNumber = other._data1lineNumber;
64 _data2lineNumber = other._data2lineNumber;
65 _fileName = other._fileName;
66}
67
68
69inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
70{
71}
72
73
74inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
75{
76}
77
78
79inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(data2lineNumber), _fileName(fileName)
80{
81}
82
83
84inline CppUnitException::~CppUnitException () throw()
85{
86}
87
88
89inline CppUnitException& CppUnitException::operator = (const CppUnitException& other)
90{
91 exception::operator= (other);
92
93 if (&other != this)
94 {
95 _message = other._message;
96 _lineNumber = other._lineNumber;
97 _data1lineNumber = other._data1lineNumber;
98 _data2lineNumber = other._data2lineNumber;
99 _fileName = other._fileName;
100 }
101 return *this;
102}
103
104
105inline const char* CppUnitException::what() const throw ()
106{
107 return _message.c_str();
108}
109
110
111inline long CppUnitException::lineNumber() const
112{
113 return _lineNumber;
114}
115
116
117inline long CppUnitException::data1LineNumber() const
118{
119 return _data1lineNumber;
120}
121
122
123inline long CppUnitException::data2LineNumber() const
124{
125 return _data2lineNumber;
126}
127
128
129// The file in which the error occurred
130inline const std::string& CppUnitException::fileName() const
131{
132 return _fileName;
133}
134
135
136} // namespace CppUnit
137
138
139#endif // Poco_CppUnit_CppUnitException_INCLUDED
140