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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3991 - (show annotations)
Tue Sep 25 23:52:22 2012 UTC (6 years, 10 months ago) by caltinay
File MIME type: text/plain
File size: 4754 byte(s)
Updated doxygen cfg file and made a few first changes to doco.

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 \brief A base class for exception classes used within Esys system.
29 */
30 class EsysException : public std::exception
31 {
32
33 protected:
34
35 typedef std::exception Parent;
36
37
38 public:
39 /**
40 \brief
41 Default Constructor. Creates an exception with no message.
42 */
43 ESYSUTILS_DLL_API
44 EsysException();
45
46 /**
47 * \brief
48 Constructor which creates a EsysException with the given message
49
50 @param exceptionReason Input - Exception message.
51 */
52 ESYSUTILS_DLL_API
53 EsysException(const std::string &exceptionReason);
54
55 /**
56 * \brief
57 Constructor which creates a EsysException with the given message
58
59 @param cStr - Exception message.
60 */
61 ESYSUTILS_DLL_API
62 EsysException( const char *cStr );
63
64 /**
65 * \brief
66 Copy constructor
67
68 @param other Input - EsysException
69 */
70 ESYSUTILS_DLL_API
71 EsysException(const EsysException &other);
72
73 /// Destructor
74 ESYSUTILS_DLL_API
75 virtual ~EsysException() THROW(NO_ARG);
76
77 /**
78 \brief
79 Assignment needed to override any automatic assignment
80 of std::exception, which can potentially copy around char *'s,
81 causeing trouble in some implementations of STL.
82 It will only copy the reason string, and update the message.
83
84 @return re-assigned exception.
85 */
86 ESYSUTILS_DLL_API
87 EsysException &
88 operator=(const EsysException &other) THROW(NO_ARG);
89
90 /**
91 \brief
92 Return the exception message in the form
93 &lt;Exception Name&gt;: &lt;Exception Message&gt;
94
95 @return the exception message.
96 */
97 inline
98 const std::string & toString() const;
99
100 /**
101 \brief
102 Return the name of the exception. This is expected to be overloaded
103 in derived classes with the derived class name.
104
105 @return the name of the exception.
106 */
107 ESYSUTILS_DLL_API
108 virtual const std::string & exceptionName() const;
109
110 /**
111 \brief
112 Return a reference to the string that contains the exception reason.
113
114 @return the string for the exception reason.
115 */
116 inline
117 const std::string& reason() const;
118
119 /**
120 \brief
121 set the string for the reason for the exception.
122 This allows ousiders to modify m_reason, but the practice is discouraged.
123 If string insertions are required, use string methods.
124 */
125 inline
126 void setReason(const std::string &new_reason);
127
128 /**
129 \brief
130 Return a description of the exception in the same format as the toString
131 method.
132
133 @return a description of the exception.
134 */
135 ESYSUTILS_DLL_API
136 inline
137 virtual const char* what() const THROW(NO_ARG);
138
139
140 /**
141 \brief
142 update m_exceptionMessage after a reason update.
143 **/
144 inline
145 void updateMessage();
146
147
148 private:
149 //
150 // the exception reason
151 std::string m_reason;
152
153 //
154 // the full exception message
155 std::string m_exceptionMessage;
156
157 //
158 // the exception name is immutable and class-wide.
159 // Inheritor note; you need one of these too.
160 // and an overloaded exceptionName() in your .cpp implementation file.
161 static const std::string exceptionNameValue;
162
163 };
164
165 /**
166 \brief
167 Stream insertion (print) operator for EsysExceptions
168
169 @param output Input - Output stream.
170 @param inException Input - The exception to be inserted into the output
171 stream.
172 */
173 ESYSUTILS_DLL_API
174 std::ostream &operator<<(std::ostream &output, EsysException &inException);
175
176
177 ////////////////////////////////////////////////////////////////////
178
179 const std::string & EsysException::reason() const
180 {
181 return m_reason;
182 }
183
184 // return the message as a std::string
185 const std::string & EsysException::toString() const
186 {
187 return m_exceptionMessage;
188 }
189
190 void EsysException::setReason(const std::string &new_reason)
191 {
192 m_reason = new_reason;
193 updateMessage();
194 }
195
196 const char* EsysException::what() const THROW(NO_ARG)
197 {
198 return m_exceptionMessage.c_str();
199 }
200
201 void EsysException::updateMessage()
202 {
203 m_exceptionMessage = exceptionName() + ": " + m_reason;
204 }
205
206 }
207
208 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26