You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2008/02/22 20:14:09 UTC

svn commit: r630296 - in /incubator/qpid/trunk/qpid/cpp/src/qpid: Exception.cpp Exception.h

Author: aconway
Date: Fri Feb 22 11:14:05 2008
New Revision: 630296

URL: http://svn.apache.org/viewvc?rev=630296&view=rev
Log:
Provide separate name, message and error code on all Exceptions.

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp?rev=630296&r1=630295&r2=630296&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp Fri Feb 22 11:14:05 2008
@@ -32,20 +32,31 @@
     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

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h?rev=630296&r1=630295&r2=630296&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h Fri Feb 22 11:14:05 2008
@@ -40,13 +40,27 @@
 class Exception : public std::exception
 {
   public:
-    explicit Exception(const std::string& str=std::string()) throw();
+    explicit Exception(const std::string& message=std::string(),
+                       const std::string& name=std::string(),
+                       uint16_t code=0) throw();
+    
     virtual ~Exception() throw();
+
+    // returns "name: message"
+    virtual const char* what() const throw();
+
+    virtual std::string getName() const throw();
+    virtual std::string getMessage() const throw();
+    virtual uint16_t getCode() const throw();
+
+    // FIXME aconway 2008-02-21: backwards compat, remove?
+    std::string str() const throw() { return getMessage(); } 
     
-    virtual const char *what() const throw();
-    virtual std::string str() const throw();
   private:
-    std::string msg;
+    const std::string message;
+    const std::string name;
+    const uint16_t code;
+    const std::string whatStr;
 };
 
 struct ChannelException : public Exception {
@@ -62,8 +76,7 @@
 };
 
 struct ClosedException : public Exception {
-    static const std::string CLOSED_MESSAGE;
-    ClosedException(const std::string& msg=CLOSED_MESSAGE) : Exception(msg) {}
+    ClosedException(const std::string& msg=std::string());
 };
 
 } // namespace qpid