/[escript]/branches/windows_from_1431_trunk/esysUtils/src/EsysException.h
ViewVC logotype

Contents of /branches/windows_from_1431_trunk/esysUtils/src/EsysException.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1441 - (show annotations)
Thu Feb 28 06:50:26 2008 UTC (12 years, 9 months ago) by trankine
File MIME type: text/plain
File size: 4444 byte(s)
We have a successful compile & link of escript & esysUtils.
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
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 public:
47 /**
48 \brief
49 Default Constructor. Creates an exception with no message.
50 */
51 EsysException();
52
53 /**
54 * \brief
55 Constructor which creates a EsysException with the given message
56
57 @param exceptionReason Input - Exception message.
58 */
59 EsysException(const std::string &exceptionReason);
60
61 /**
62 * \brief
63 Constructor which creates a EsysException with the given message
64
65 @param cStr - Exception message.
66 */
67 EsysException( const char *cStr );
68
69 /**
70 * \brief
71 Copy constructor
72
73 @param inException Input - EsysException
74 */
75 EsysException(const EsysException &inException);
76
77 /// Destructor
78 virtual ~EsysException();
79
80 /**
81 \brief
82 Assignment operator.
83
84 @param inException Input - Exception to be copied.
85 */
86 EsysException &operator=(const EsysException &inException);
87
88 /**
89 \brief
90 Return the exception message in the form
91 &lt;Exception Name&gt;: &lt;Exception Message&gt;
92
93 @return the exception message.
94 */
95 const std::string & toString() const;
96
97 /**
98 \brief
99 Return the name of the exception. This is expected to be overloaded
100 in derived classes with the derived class name.
101
102 @return the name of the exception.
103 */
104 virtual const std::string & exceptionName() const;
105
106 /**
107 \brief
108 Return a reference to the string that contains the exception reason.
109
110 @return the string for the exception reason.
111 */
112 const std::string& reason() const;
113
114 /**
115 \brief
116 set the string for the reason for the exception.
117 This allows ousiders to modify m_reason, but the practice is discouraged.
118 If string insertions are required, use string methods.
119 */
120 void setReason(const std::string &new_reason);
121
122 /**
123 \brief
124 Return a description of the exception in the same format as the toString
125 method.
126
127 @return a description of the exception.
128 */
129 virtual const char* what() const throw();
130
131
132 private:
133 /**
134 \brief
135 update m_exceptionMessage after a reason update.
136 **/
137 void updateMessage();
138
139 //
140 // the exception reason
141 std::string m_reason;
142
143 //
144 // the full exception message
145 std::string m_exceptionMessage;
146
147 //
148 // the exception name is immutable and class-wide.
149 // Inheritor note; you need one of these too.
150 // and an overloaded exceptionName() in your .cpp implementation file.
151 static const std::string exceptionNameValue;
152
153 };
154
155 /**
156 \brief
157 Stream insertion (print) operator for EsysExceptions
158
159 @param output Input - Output stream.
160 @param inException Input - The exception to be inserted into the output
161 stream.
162 */
163 std::ostream &operator<<(std::ostream &output, EsysException &inException);
164
165
166 ////////////////////////////////////////////////////////////////////
167
168 inline
169 const std::string & EsysException::reason() const
170 {
171 return m_reason;
172 }
173
174 // return the message as a std::string
175 inline
176 const std::string & EsysException::toString() const
177 {
178 return m_exceptionMessage;
179 }
180
181 inline
182 void EsysException::setReason(const std::string &new_reason)
183 {
184 m_reason = new_reason;
185 updateMessage();
186 }
187
188 inline
189 const char* EsysException::what() const
190 {
191 return m_exceptionMessage.c_str();
192 }
193
194
195
196 inline
197 void EsysException::updateMessage()
198 {
199 m_exceptionMessage = exceptionName() + ": " + m_reason;
200 }
201
202 }
203
204 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26