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

Annotation of /trunk/tools/CppUnitTest/src/CppUnitException.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (12 years, 1 month ago) by trankine
Original Path: temp/tools/CppUnitTest/src/CppUnitException.h
File MIME type: text/plain
File size: 5232 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 gross 700 //
2     // Permission to reproduce and create derivative works from the Software ("Software Derivative Works")
3     // is hereby granted to you under the copyright of Michael Feathers. Michael Feathers also grants you
4     // the right to distribute the Software and Software Derivative Works.
5     //
6     // Michael Feathers licenses the Software to you on an "AS IS" basis, without warranty of any kind.
7     // Michael Feathers HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED,
8     // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, NON INFRINGEMENT
9     // AND FITNESS FOR A PARTICULAR PURPOSE.  You are solely responsible for determining the appropriateness
10     // of using the Software and assume all risks associated with the use and distribution of this Software,
11     // including but not limited to the risks of program errors, damage to or loss of data, programs or
12     // equipment, and unavailability or interruption of operations.  MICHAEL FEATHERS WILL NOT BE
13     // LIABLE FOR ANY DIRECT DAMAGES OR FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC
14     // CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF MICHAEL FEATHERS HAD BEEN ADVISED
15     // OF THE POSSIBILITY OF SUCH DAMAGE.  Michael Feathers will not be liable for the loss of, or damage
16     // to, your records or data, or any damages claimed by you based on a third party claim.
17     //
18     // You agree to distribute the Software and any Software Derivatives under a license agreement that:
19     //
20     // 1) is sufficient to notify all licensees of the Software and Software Derivatives that Michael
21     // Feathers assumes no liability for any claim that may arise regarding the Software or
22     // Software Derivatives, and
23     // 2) that disclaims all warranties, both express and implied, from Michael Feathers regarding the
24     // Software and Software Derivatives.  (If you include this Agreement with any distribution
25     // of the Software and Software Derivatives you will have meet this requirement) You agree that
26     // you will not delete any copyright notices in the Software.
27     //
28     // This Agreement is the exclusive statement of your rights in the Software as provided by Michael
29     // Feathers. Except for the licenses granted to you in the second paragraph above, no other licenses
30     // are granted hereunder, by estoppel, implication or otherwise.
31     //
32 jgs 82 #ifndef CPPUNIT_CPPUNITEXCEPTION_H
33     #define CPPUNIT_CPPUNITEXCEPTION_H
34    
35     /*
36     * CppUnitException is an exception that serves
37     * descriptive strings through its what () method
38     *
39     */
40    
41     #include <exception>
42     #include <string>
43 gross 700 #include "CppUnitTestNamespace.h"
44 jgs 82
45     BEGIN_NAMESPACE_CPPUNITTEST
46    
47     #define CPPUNIT_UNKNOWNFILENAME "<unknown>"
48     #define CPPUNIT_UNKNOWNLINENUMBER (-1)
49    
50     //#if defined (__sgi) && ( _COMPILER_VERSION < 730 )
51     //class exception {
52     // public:
53     // virtual ~exception() {}
54     // virtual const char* what() const throw() { return ""; }
55     //};
56     //#endif
57    
58     class CppUnitException : public std::exception
59     {
60     public:
61     CppUnitException (std::string message = "",
62     long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,
63     std::string fileName = CPPUNIT_UNKNOWNFILENAME);
64     CppUnitException (const CppUnitException& other);
65    
66     virtual ~CppUnitException () throw() ;
67    
68     CppUnitException& operator= (const CppUnitException& other);
69    
70     const char *what() const throw ();
71    
72     long lineNumber ();
73     std::string fileName ();
74    
75     private:
76     std::string m_message;
77     long m_lineNumber;
78     std::string m_fileName;
79    
80     };
81    
82    
83     // Construct the exception
84     inline CppUnitException::CppUnitException (const CppUnitException& other)
85     : std::exception (other)
86     {
87     m_message = other.m_message;
88     m_lineNumber = other.m_lineNumber;
89     m_fileName = other.m_fileName;
90     }
91    
92     inline CppUnitException::CppUnitException (std::string message, long lineNumber, std::string fileName)
93     : m_message (message), m_lineNumber (lineNumber), m_fileName (fileName)
94     {}
95    
96    
97     // Destruct the exception
98     inline CppUnitException::~CppUnitException () throw()
99     {}
100    
101    
102     // Perform an assignment
103     inline CppUnitException& CppUnitException::operator= (const CppUnitException& other)
104     {
105     #if defined MSWIN
106     //
107     // ms visual c++ compiler doesn't like the std::exception::operator=
108     // approach and the SG 7.2.1 compiler doesn't accept the this->exception
109     // style
110     //
111     this->exception::operator= (other);
112     #else
113     std::exception::operator= (other);
114     #endif
115    
116     if (&other != this) {
117     m_message = other.m_message;
118     m_lineNumber = other.m_lineNumber;
119     m_fileName = other.m_fileName;
120     }
121    
122     return *this;
123     }
124    
125    
126     // Return descriptive message
127     inline const char *CppUnitException::what() const throw ()
128     { return m_message.c_str (); }
129    
130     // The line on which the error occurred
131     inline long CppUnitException::lineNumber ()
132     { return m_lineNumber; }
133    
134    
135     // The file in which the error occurred
136     inline std::string CppUnitException::fileName ()
137     { return m_fileName; }
138    
139     END_NAMESPACE_CPPUNITTEST
140    
141     #endif
142    
143    
144    
145    
146    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26