1 |
ksteube |
1312 |
|
2 |
|
|
/* $Id$ */ |
3 |
|
|
|
4 |
|
|
/******************************************************* |
5 |
trankine |
1441 |
* |
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 |
ksteube |
1312 |
|
16 |
jgs |
82 |
#ifndef ESYSEXCEPTION_H |
17 |
|
|
#define ESYSEXCEPTION_H |
18 |
woo409 |
757 |
#include "system_dep.h" |
19 |
jgs |
82 |
|
20 |
|
|
#include <string> |
21 |
|
|
#include <exception> |
22 |
|
|
|
23 |
trankine |
1439 |
namespace esysUtils |
24 |
|
|
{ |
25 |
|
|
/** |
26 |
|
|
\page esys_exception Esys Exceptions |
27 |
|
|
A base class for exception classes used within Esys system. |
28 |
jgs |
82 |
|
29 |
trankine |
1439 |
\version 1.0.0 |
30 |
jgs |
82 |
|
31 |
trankine |
1439 |
\section class_desc Class Description: |
32 |
|
|
A base class for exception classes used within Esys system. |
33 |
jgs |
82 |
|
34 |
trankine |
1439 |
\section class_limits Class Limitations: |
35 |
|
|
None |
36 |
jgs |
82 |
|
37 |
trankine |
1439 |
\section class_conds Class Conditions of Use: |
38 |
|
|
None |
39 |
jgs |
82 |
|
40 |
trankine |
1439 |
\section throws Throws: |
41 |
|
|
None |
42 |
jgs |
82 |
|
43 |
trankine |
1439 |
*/ |
44 |
|
|
class EsysException:public std::exception { |
45 |
|
|
|
46 |
jgs |
82 |
public: |
47 |
trankine |
1439 |
/** |
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 |
jgs |
82 |
|
57 |
trankine |
1439 |
@param exceptionReason Input - Exception message. |
58 |
|
|
*/ |
59 |
|
|
EsysException(const std::string &exceptionReason); |
60 |
jgs |
121 |
|
61 |
trankine |
1439 |
/** |
62 |
|
|
* \brief |
63 |
|
|
Constructor which creates a EsysException with the given message |
64 |
jgs |
121 |
|
65 |
trankine |
1439 |
@param cStr - Exception message. |
66 |
|
|
*/ |
67 |
|
|
EsysException( const char *cStr ); |
68 |
jgs |
121 |
|
69 |
trankine |
1439 |
/** |
70 |
|
|
* \brief |
71 |
|
|
Copy constructor |
72 |
jgs |
121 |
|
73 |
trankine |
1439 |
@param inException Input - EsysException |
74 |
|
|
*/ |
75 |
|
|
EsysException(const EsysException &inException); |
76 |
jgs |
121 |
|
77 |
trankine |
1439 |
/// 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 |
|
|
<Exception Name>: <Exception Message> |
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 |
jgs |
121 |
|
110 |
trankine |
1439 |
@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 |
trankine |
1441 |
void updateMessage(); |
138 |
trankine |
1439 |
|
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 |
trankine |
1441 |
// and an overloaded exceptionName() in your .cpp implementation file. |
151 |
trankine |
1439 |
static const std::string exceptionNameValue; |
152 |
|
|
|
153 |
|
|
}; |
154 |
|
|
|
155 |
jgs |
82 |
/** |
156 |
trankine |
1439 |
\brief |
157 |
|
|
Stream insertion (print) operator for EsysExceptions |
158 |
jgs |
121 |
|
159 |
trankine |
1439 |
@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 |
jgs |
121 |
|
165 |
jgs |
82 |
|
166 |
trankine |
1439 |
//////////////////////////////////////////////////////////////////// |
167 |
|
|
|
168 |
trankine |
1441 |
inline |
169 |
trankine |
1439 |
const std::string & EsysException::reason() const |
170 |
|
|
{ |
171 |
|
|
return m_reason; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
// return the message as a std::string |
175 |
trankine |
1441 |
inline |
176 |
trankine |
1439 |
const std::string & EsysException::toString() const |
177 |
|
|
{ |
178 |
|
|
return m_exceptionMessage; |
179 |
|
|
} |
180 |
|
|
|
181 |
trankine |
1441 |
inline |
182 |
trankine |
1439 |
void EsysException::setReason(const std::string &new_reason) |
183 |
|
|
{ |
184 |
|
|
m_reason = new_reason; |
185 |
|
|
updateMessage(); |
186 |
|
|
} |
187 |
|
|
|
188 |
trankine |
1441 |
inline |
189 |
trankine |
1439 |
const char* EsysException::what() const |
190 |
|
|
{ |
191 |
|
|
return m_exceptionMessage.c_str(); |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
trankine |
1441 |
inline |
197 |
trankine |
1439 |
void EsysException::updateMessage() |
198 |
|
|
{ |
199 |
|
|
m_exceptionMessage = exceptionName() + ": " + m_reason; |
200 |
|
|
} |
201 |
|
|
|
202 |
jgs |
82 |
} |
203 |
|
|
|
204 |
|
|
#endif |