summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/Exception.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-02-22 19:14:05 +0000
committerAlan Conway <aconway@apache.org>2008-02-22 19:14:05 +0000
commit0375ee9a77888a4901dcb093af1683c953cfcb37 (patch)
tree047415b956f968f4610f6c0d9156a82c10d27400 /cpp/src/qpid/Exception.cpp
parentbaf3d1551e30c0a522a52837c84b3b7c1c411aa0 (diff)
downloadqpid-python-0375ee9a77888a4901dcb093af1683c953cfcb37.tar.gz
Provide separate name, message and error code on all Exceptions.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@630296 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Exception.cpp')
-rw-r--r--cpp/src/qpid/Exception.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/cpp/src/qpid/Exception.cpp b/cpp/src/qpid/Exception.cpp
index 07f157cfc3..17f0d5029c 100644
--- a/cpp/src/qpid/Exception.cpp
+++ b/cpp/src/qpid/Exception.cpp
@@ -32,20 +32,31 @@ std::string strError(int err) {
return std::string(strerror_r(err, buf, sizeof(buf)));
}
-Exception::Exception(const std::string& s) throw() : msg(s) {
- QPID_LOG(warning, "Exception: " << msg);
+Exception::Exception(const std::string& msg,
+ const std::string& nm,
+ uint16_t cd) throw()
+ : message(msg), name(nm), code(cd),
+ whatStr((name.empty() ? "" : name + ": ")+ msg)
+{
+ QPID_LOG(warning, "Exception: " << whatStr);
}
Exception::~Exception() throw() {}
-std::string Exception::str() const throw() {
- if (msg.empty())
- const_cast<std::string&>(msg).assign(typeid(*this).name());
- return msg;
+std::string Exception::getMessage() const throw() { return message; }
+
+std::string Exception::getName() const throw() {
+ return name.empty() ? typeid(*this).name() : name;
}
-const char* Exception::what() const throw() { return str().c_str(); }
+uint16_t Exception::getCode() const throw() { return code; }
+
+const char* Exception::what() const throw() {
+ if (whatStr.empty()) return typeid(*this).name();
+ else return whatStr.c_str();
+}
-const std::string ClosedException::CLOSED_MESSAGE("Closed");
+ClosedException::ClosedException(const std::string& msg)
+ : Exception(msg, "ClosedException") {}
} // namespace qpid