/[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 1449 - (show annotations)
Thu Feb 28 13:40:48 2008 UTC (12 years, 4 months ago) by phornby
File MIME type: text/plain
File size: 4352 byte(s)
Have to go to another machine, my editor keeps crashing....


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 EsysException();
59
60 /**
61 * \brief
62 Constructor which creates a EsysException with the given message
63
64 @param exceptionReason Input - Exception message.
65 */
66 EsysException(const std::string &exceptionReason);
67
68 /**
69 * \brief
70 Constructor which creates a EsysException with the given message
71
72 @param cStr - Exception message.
73 */
74 EsysException( const char *cStr );
75
76 /**
77 * \brief
78 Copy constructor
79
80 @param other Input - EsysException
81 */
82 EsysException(const EsysException &other);
83
84 /// Destructor
85 virtual ~EsysException() THROW();
86
87 /**
88 \brief
89 Return the exception message in the form
90 &lt;Exception Name&gt;: &lt;Exception Message&gt;
91
92 @return the exception message.
93 */
94 const std::string & toString() const;
95
96 /**
97 \brief
98 Return the name of the exception. This is expected to be overloaded
99 in derived classes with the derived class name.
100
101 @return the name of the exception.
102 */
103 virtual const std::string & exceptionName() const;
104
105 /**
106 \brief
107 Return a reference to the string that contains the exception reason.
108
109 @return the string for the exception reason.
110 */
111 const std::string& reason() const;
112
113 /**
114 \brief
115 set the string for the reason for the exception.
116 This allows ousiders to modify m_reason, but the practice is discouraged.
117 If string insertions are required, use string methods.
118 */
119 void setReason(const std::string &new_reason);
120
121 /**
122 \brief
123 Return a description of the exception in the same format as the toString
124 method.
125
126 @return a description of the exception.
127 */
128 virtual const char* what() const THROW();
129
130
131 /**
132 \brief
133 update m_exceptionMessage after a reason update.
134 **/
135 void updateMessage();
136
137
138 private:
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 THROW()
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