2 |
/* $Id$ */ |
/* $Id$ */ |
3 |
|
|
4 |
/******************************************************* |
/******************************************************* |
5 |
* |
* |
6 |
* Copyright 2003-2007 by ACceSS MNRF |
* Copyright 2003-2007 by ACceSS MNRF |
7 |
* Copyright 2007 by University of Queensland |
* Copyright 2007 by University of Queensland |
8 |
* |
* |
9 |
* http://esscc.uq.edu.au |
* http://esscc.uq.edu.au |
10 |
* Primary Business: Queensland, Australia |
* Primary Business: Queensland, Australia |
11 |
* Licensed under the Open Software License version 3.0 |
* Licensed under the Open Software License version 3.0 |
12 |
* http://www.opensource.org/licenses/osl-3.0.php |
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
* |
* |
14 |
*******************************************************/ |
*******************************************************/ |
15 |
|
|
16 |
#ifndef ESYSEXCEPTION_H |
#ifndef ESYSEXCEPTION_H |
17 |
#define ESYSEXCEPTION_H |
#define ESYSEXCEPTION_H |
19 |
|
|
20 |
#include <string> |
#include <string> |
21 |
#include <exception> |
#include <exception> |
|
#include <algorithm> |
|
22 |
|
|
23 |
namespace esysUtils |
namespace esysUtils |
24 |
{ |
{ |
109 |
|
|
110 |
@return the string for the exception reason. |
@return the string for the exception reason. |
111 |
*/ |
*/ |
|
inline |
|
112 |
const std::string& reason() const; |
const std::string& reason() const; |
113 |
|
|
114 |
/** |
/** |
134 |
\brief |
\brief |
135 |
update m_exceptionMessage after a reason update. |
update m_exceptionMessage after a reason update. |
136 |
**/ |
**/ |
137 |
inline void updateMessage(); |
void updateMessage(); |
138 |
|
|
139 |
// |
// |
140 |
// the exception reason |
// the exception reason |
147 |
// |
// |
148 |
// the exception name is immutable and class-wide. |
// the exception name is immutable and class-wide. |
149 |
// Inheritor note; you need one of these too. |
// Inheritor note; you need one of these too. |
150 |
// and an overloaded exceptionName in your .cpp implementation file. |
// and an overloaded exceptionName() in your .cpp implementation file. |
151 |
static const std::string exceptionNameValue; |
static const std::string exceptionNameValue; |
152 |
|
|
153 |
}; |
}; |
165 |
|
|
166 |
//////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////// |
167 |
|
|
168 |
|
inline |
169 |
const std::string & EsysException::reason() const |
const std::string & EsysException::reason() const |
170 |
{ |
{ |
171 |
return m_reason; |
return m_reason; |
172 |
} |
} |
173 |
|
|
174 |
// return the message as a std::string |
// return the message as a std::string |
175 |
|
inline |
176 |
const std::string & EsysException::toString() const |
const std::string & EsysException::toString() const |
177 |
{ |
{ |
178 |
return m_exceptionMessage; |
return m_exceptionMessage; |
179 |
} |
} |
180 |
|
|
181 |
|
inline |
182 |
void EsysException::setReason(const std::string &new_reason) |
void EsysException::setReason(const std::string &new_reason) |
183 |
{ |
{ |
184 |
m_reason = new_reason; |
m_reason = new_reason; |
185 |
updateMessage(); |
updateMessage(); |
186 |
} |
} |
187 |
|
|
188 |
|
inline |
189 |
const char* EsysException::what() const |
const char* EsysException::what() const |
190 |
{ |
{ |
191 |
return m_exceptionMessage.c_str(); |
return m_exceptionMessage.c_str(); |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
inline |
197 |
void EsysException::updateMessage() |
void EsysException::updateMessage() |
198 |
{ |
{ |
199 |
m_exceptionMessage = exceptionName() + ": " + m_reason; |
m_exceptionMessage = exceptionName() + ": " + m_reason; |