/[escript]/trunk/esysUtils/src/EsysException.h
ViewVC logotype

Contents of /trunk/esysUtils/src/EsysException.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1649 - (show annotations)
Tue Jul 15 08:41:02 2008 UTC (10 years, 9 months ago) by phornby
File MIME type: text/plain
File size: 4941 byte(s)
Make operator=() on exception non-virtual. Should silence the Altix compiler.
However, if an exception is cast to another parent type, and
operator=() is called when the exception so cast is an l-value in the assignment,
an "incomplete" assignment will occur, copying only the parent class members of the 
l-value in the assignmnet.
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #ifndef ESYSEXCEPTION_H
17 #define ESYSEXCEPTION_H
18 #include "system_dep.h"
19
20 #include <string>
21 #include <exception>
22 #include <iostream>
23
24 namespace esysUtils
25 {
26 /**
27 \page esys_exception Esys Exceptions
28 A base class for exception classes used within Esys system.
29
30 \version 1.0.0
31
32 \section class_desc Class Description:
33 A base class for exception classes used within Esys system.
34
35 \section class_limits Class Limitations:
36 None
37
38 \section class_conds Class Conditions of Use:
39 None
40
41 \section throws Throws:
42 None
43
44 */
45 class EsysException : public std::exception
46 {
47
48 protected:
49
50 typedef std::exception Parent;
51
52
53 public:
54 /**
55 \brief
56 Default Constructor. Creates an exception with no message.
57 */
58 ESYSUTILS_DLL_API
59 EsysException();
60
61 /**
62 * \brief
63 Constructor which creates a EsysException with the given message
64
65 @param exceptionReason Input - Exception message.
66 */
67 ESYSUTILS_DLL_API
68 EsysException(const std::string &exceptionReason);
69
70 /**
71 * \brief
72 Constructor which creates a EsysException with the given message
73
74 @param cStr - Exception message.
75 */
76 ESYSUTILS_DLL_API
77 EsysException( const char *cStr );
78
79 /**
80 * \brief
81 Copy constructor
82
83 @param other Input - EsysException
84 */
85 ESYSUTILS_DLL_API
86 EsysException(const EsysException &other);
87
88 /// Destructor
89 ESYSUTILS_DLL_API
90 virtual ~EsysException() THROW_ANY;
91
92 /**
93 \brief
94 Assignment needed to override any automatic assignment
95 of std::exception, which can potentially copy around char *'s,
96 causeing trouble in some implementations of STL.
97 It will only copy the reason string, and update the message.
98
99 @return re-assigned exception.
100 */
101 ESYSUTILS_DLL_API
102 EsysException &
103 operator=(const EsysException &other) THROW_ANY;
104
105 /**
106 \brief
107 Return the exception message in the form
108 &lt;Exception Name&gt;: &lt;Exception Message&gt;
109
110 @return the exception message.
111 */
112 inline
113 const std::string & toString() const;
114
115 /**
116 \brief
117 Return the name of the exception. This is expected to be overloaded
118 in derived classes with the derived class name.
119
120 @return the name of the exception.
121 */
122 ESYSUTILS_DLL_API
123 virtual const std::string & exceptionName() const;
124
125 /**
126 \brief
127 Return a reference to the string that contains the exception reason.
128
129 @return the string for the exception reason.
130 */
131 inline
132 const std::string& reason() const;
133
134 /**
135 \brief
136 set the string for the reason for the exception.
137 This allows ousiders to modify m_reason, but the practice is discouraged.
138 If string insertions are required, use string methods.
139 */
140 inline
141 void setReason(const std::string &new_reason);
142
143 /**
144 \brief
145 Return a description of the exception in the same format as the toString
146 method.
147
148 @return a description of the exception.
149 */
150 ESYSUTILS_DLL_API
151 inline
152 virtual const char* what() const THROW_ANY;
153
154
155 /**
156 \brief
157 update m_exceptionMessage after a reason update.
158 **/
159 inline
160 void updateMessage();
161
162
163 private:
164 //
165 // the exception reason
166 std::string m_reason;
167
168 //
169 // the full exception message
170 std::string m_exceptionMessage;
171
172 //
173 // the exception name is immutable and class-wide.
174 // Inheritor note; you need one of these too.
175 // and an overloaded exceptionName() in your .cpp implementation file.
176 static const std::string exceptionNameValue;
177
178 };
179
180 /**
181 \brief
182 Stream insertion (print) operator for EsysExceptions
183
184 @param output Input - Output stream.
185 @param inException Input - The exception to be inserted into the output
186 stream.
187 */
188 ESYSUTILS_DLL_API
189 std::ostream &operator<<(std::ostream &output, EsysException &inException);
190
191
192 ////////////////////////////////////////////////////////////////////
193
194 const std::string & EsysException::reason() const
195 {
196 return m_reason;
197 }
198
199 // return the message as a std::string
200 const std::string & EsysException::toString() const
201 {
202 return m_exceptionMessage;
203 }
204
205 void EsysException::setReason(const std::string &new_reason)
206 {
207 m_reason = new_reason;
208 updateMessage();
209 }
210
211 const char* EsysException::what() const THROW_ANY
212 {
213 return m_exceptionMessage.c_str();
214 }
215
216 void EsysException::updateMessage()
217 {
218 m_exceptionMessage = exceptionName() + ": " + m_reason;
219 }
220
221 }
222
223 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26