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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2019 - (show annotations)
Mon Nov 10 13:49:00 2008 UTC (10 years, 9 months ago) by phornby
File MIME type: text/plain
File size: 4932 byte(s)
Yet another concerted effort to handle missing macro arguments
in a portable way.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26