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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26