Clean up exception classes 15/28715/4
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tue, 14 Oct 2014 07:21:41 +0000 (09:21 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 16 Oct 2014 11:24:27 +0000 (13:24 +0200)
Some minor clean-ups in exceptions classes:
* remove "noexcept" keyword from exception classes;
* catch exceptions in Exception::what();
* correcting comments;
* adding missing virtual keyword;
* rearranging public and private sections.

Change-Id: I99c382838adb22429a7ea8ac35974c988b3d3f33

19 files changed:
src/common/exceptions/BucketDeserializationException.h
src/common/exceptions/BucketNotExistsException.h
src/common/exceptions/BucketRecordCorruptedException.h
src/common/exceptions/BucketSerializationException.h
src/common/exceptions/CannotCreateFileException.h
src/common/exceptions/DatabaseException.h
src/common/exceptions/DefaultBucketDeletionException.h
src/common/exceptions/DefaultBucketSetNoneException.h
src/common/exceptions/DescriptorNotExistsException.h
src/common/exceptions/Exception.h
src/common/exceptions/FileNotFoundException.h
src/common/exceptions/InitException.h
src/common/exceptions/InvalidProtocolException.h
src/common/exceptions/NoMemoryException.h
src/common/exceptions/NotImplementedException.h
src/common/exceptions/NullPointerException.h
src/common/exceptions/OutOfDataException.h
src/common/exceptions/PluginNotFoundException.h
src/common/exceptions/UnexpectedErrorException.h

index c6b6f1d..c5670c8 100644 (file)
@@ -30,7 +30,7 @@ namespace Cynara {
 class BucketDeserializationException : public DatabaseException {
 public:
     BucketDeserializationException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {}
-    ~BucketDeserializationException() noexcept {};
+    virtual ~BucketDeserializationException() {};
 
     const std::string message(void) const {
         if (m_message.empty()) {
index 7802210..9ba9505 100644 (file)
@@ -34,19 +34,18 @@ class BucketNotExistsException : public Exception {
 public:
     BucketNotExistsException() = delete;
     BucketNotExistsException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {}
-    virtual ~BucketNotExistsException() noexcept {};
+    virtual ~BucketNotExistsException() {};
 
     virtual const std::string message(void) const {
         return "BucketNotExistsException";
     }
 
-private:
-    PolicyBucketId m_bucketId;
-
-public:
-    const PolicyBucketId &bucketId() const {
+    const PolicyBucketId &bucketId(void) const {
         return m_bucketId;
     }
+
+private:
+    PolicyBucketId m_bucketId;
 };
 
 } /* namespace Cynara */
index 4511fb5..92b29f7 100644 (file)
@@ -31,7 +31,7 @@ namespace Cynara {
 class BucketRecordCorruptedException : public DatabaseException {
 public:
     BucketRecordCorruptedException(void) = delete;
-    virtual ~BucketRecordCorruptedException() noexcept {};
+    virtual ~BucketRecordCorruptedException() {};
 
     BucketRecordCorruptedException(const std::string &line)
         : m_lineNumber(0), m_line(line)  {}
@@ -60,6 +60,18 @@ public:
         return m_whatMsg;
     }
 
+    const std::string &filename(void) const {
+        return m_filename;
+    }
+
+    const std::string &line(void) const {
+        return m_line;
+    }
+
+    size_t lineNumber(void) const {
+        return m_lineNumber;
+    }
+
 protected:
     inline std::string slicedLine(void) const {
         return m_line.substr(0, 50) + (m_line.size() > 50 ? "..." : "");
@@ -80,19 +92,6 @@ private:
     std::string m_line;
     std::string m_filename;
     mutable std::string m_whatMsg;
-
-public:
-    const std::string &filename(void) const {
-        return m_filename;
-    }
-
-    const std::string &line(void) const {
-        return m_line;
-    }
-
-    size_t lineNumber(void) const {
-        return m_lineNumber;
-    }
 };
 
 } /* namespace Cynara */
index f6dba4c..1e02823 100644 (file)
@@ -30,7 +30,7 @@ namespace Cynara {
 class BucketSerializationException : public DatabaseException {
 public:
     BucketSerializationException(const PolicyBucketId &bucketId) : m_bucketId(bucketId) {}
-    ~BucketSerializationException() noexcept {};
+    virtual ~BucketSerializationException() {};
 
     const std::string message(void) const {
         if (m_message.empty()) {
index 4195156..67c1d67 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class CannotCreateFileException : public DatabaseException {
 public:
     CannotCreateFileException(const std::string &filename) : m_filename(filename) {};
-    virtual ~CannotCreateFileException() noexcept {};
+    virtual ~CannotCreateFileException() {};
 
     const std::string message(void) const {
         if (m_message.empty()) {
index 9cbd2b4..834d524 100644 (file)
@@ -27,7 +27,8 @@
 namespace Cynara {
 
 class DatabaseException : public Exception {
-
+public:
+    virtual ~DatabaseException() {};
 };
 
 } /* namespace Cynara */
index 9b75a00..a4742be 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class DefaultBucketDeletionException : public Exception {
 public:
     DefaultBucketDeletionException() = default;
-    virtual ~DefaultBucketDeletionException() noexcept {};
+    virtual ~DefaultBucketDeletionException() {};
 
     virtual const std::string message(void) const {
         return "DefaultBucketDeletionException";
index b7975cd..243c4d8 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class DefaultBucketSetNoneException : public Exception {
 public:
     DefaultBucketSetNoneException() = default;
-    virtual ~DefaultBucketSetNoneException() noexcept {};
+    virtual ~DefaultBucketSetNoneException() {};
 
     virtual const std::string message(void) const {
         return "DefaultBucketSetNoneException";
index badb64a..3535b91 100644 (file)
@@ -32,9 +32,6 @@
 namespace Cynara {
 
 class DescriptorNotExistsException : public Exception {
-private:
-    std::string m_whatMsg;
-
 public:
     DescriptorNotExistsException() = delete;
     DescriptorNotExistsException(int desc) {
@@ -43,11 +40,14 @@ public:
         m_whatMsg = stream.str();
     }
 
-    virtual ~DescriptorNotExistsException() noexcept {};
+    virtual ~DescriptorNotExistsException() {};
 
     virtual const std::string message(void) const {
         return m_whatMsg;
     }
+
+private:
+    std::string m_whatMsg;
 };
 
 } // namespace Cynara
index 4f5f5eb..c5eb709 100644 (file)
@@ -33,11 +33,15 @@ public:
         m_backtrace = Backtrace::getBacktrace();
     }
 
-    virtual ~Exception() noexcept {};
+    virtual ~Exception() {};
 
     virtual const char *what(void) const noexcept {
         if(m_whatMessage.empty()) {
-            m_whatMessage = message() + " From: " + m_backtrace;
+            try {
+                m_whatMessage = message() + " From: " + m_backtrace;
+            }
+            catch (...) {
+            }
         }
         return m_whatMessage.c_str();
     }
index e7aeead..4c446e2 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class FileNotFoundException : public DatabaseException {
 public:
     FileNotFoundException(const std::string &filename) : m_filename(filename) {};
-    virtual ~FileNotFoundException() noexcept {};
+    virtual ~FileNotFoundException() {};
 
     const std::string message(void) const {
         if (m_message.empty()) {
index c93155c..cdb09a2 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class InitException : public Exception {
 public:
     InitException() = default;
-    virtual ~InitException() noexcept {};
+    virtual ~InitException() {};
 
     virtual const std::string message(void) const {
         return "InitException";
index 89d0e4b..9b6a740 100644 (file)
@@ -38,11 +38,6 @@ public:
         Other
     };
 
-private:
-    std::string m_whatMessage;
-    ExceptionType m_exceptionType;
-
-public:
     InvalidProtocolException(ExceptionType exceptionType) :
         m_exceptionType(exceptionType) {
         switch(m_exceptionType) {
@@ -56,18 +51,21 @@ public:
                 m_whatMessage = "Unknown problem";
                 break;
         }
-
     }
 
-    virtual ~InvalidProtocolException() noexcept {};
+    virtual ~InvalidProtocolException() {};
 
     virtual const std::string message(void) const {
         return m_whatMessage;
     }
 
-    ExceptionType exceptionTyp(void) const {
+    ExceptionType exceptionType(void) const {
         return m_exceptionType;
     }
+
+private:
+    std::string m_whatMessage;
+    ExceptionType m_exceptionType;
 };
 
 } // namespace Cynara
index d8a6086..2eca090 100644 (file)
@@ -37,7 +37,7 @@ public:
         m_whatMessage = "NoMemoryException with message <" + errorMsg + ">";
     }
 
-    virtual ~NoMemoryException() noexcept {};
+    virtual ~NoMemoryException() {};
 
     virtual const std::string message(void) const {
         return m_whatMessage;
index 1496fd7..8ca3762 100644 (file)
@@ -32,7 +32,7 @@ namespace Cynara {
 class NotImplementedException : public Exception {
 public:
     NotImplementedException() = default;
-    virtual ~NotImplementedException() noexcept {};
+    virtual ~NotImplementedException() {};
 
     virtual const std::string message(void) const {
         return "NotImplementedException";
index 47e4239..e735555 100644 (file)
@@ -17,7 +17,7 @@
  * @file        src/common/exceptions/NullPointerException.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  * @version     1.0
- * @brief       Implementation of OutOfDataException
+ * @brief       Implementation of NullPointerException
  */
 
 #ifndef SRC_COMMON_EXCEPTIONS_NULLPOINTEREXCEPTION_H_
@@ -31,9 +31,6 @@
 namespace Cynara {
 
 class NullPointerException : public Exception {
-private:
-    std::string m_whatMsg;
-
 public:
     NullPointerException() = delete;
     NullPointerException(const char *varName) {
@@ -42,11 +39,14 @@ public:
                   + std::string(">");
     }
 
-    virtual ~NullPointerException() noexcept {};
+    virtual ~NullPointerException() {};
 
     virtual const std::string message(void) const {
         return m_whatMsg;
     }
+
+private:
+    std::string m_whatMsg;
 };
 
 } // namespace Cynara
index 716df13..6420819 100644 (file)
@@ -32,9 +32,6 @@
 namespace Cynara {
 
 class OutOfDataException : public Exception {
-private:
-    std::string m_whatMsg;
-
 public:
     OutOfDataException() = delete;
     OutOfDataException(size_t dataRange, size_t accessTry) {
@@ -44,11 +41,14 @@ public:
         m_whatMsg = stream.str();
     }
 
-    virtual ~OutOfDataException() noexcept {};
+    virtual ~OutOfDataException() {};
 
     virtual const std::string message(void) const {
         return m_whatMsg;
     }
+
+private:
+    std::string m_whatMsg;
 };
 
 } // namespace Cynara
index 3604075..4492a53 100644 (file)
@@ -32,9 +32,6 @@
 namespace Cynara {
 
 class PluginNotFoundException : public Exception {
-private:
-    std::string m_whatMessage;
-
 public:
     PluginNotFoundException() = delete;
     PluginNotFoundException(const PolicyResult &result) {
@@ -45,11 +42,14 @@ public:
         m_whatMessage = stream.str();
     }
 
-    virtual ~PluginNotFoundException() noexcept {};
+    virtual ~PluginNotFoundException() {};
 
     virtual const std::string message(void) const {
         return m_whatMessage;
     }
+
+private:
+    std::string m_whatMessage;
 };
 
 } // namespace Cynara
index ed0b72c..3080c0f 100644 (file)
@@ -31,9 +31,6 @@
 namespace Cynara {
 
 class UnexpectedErrorException : public Exception {
-private:
-    std::string m_whatMessage;
-
 public:
     UnexpectedErrorException() = delete;
     UnexpectedErrorException(int errorCode, const char *errorMsg) {
@@ -49,11 +46,14 @@ public:
         m_whatMessage = stream.str();
     }
 
-    virtual ~UnexpectedErrorException() noexcept {};
+    virtual ~UnexpectedErrorException() {};
 
     virtual const std::string message(void) const {
         return m_whatMessage;
     }
+
+private:
+    std::string m_whatMessage;
 };
 
 } // namespace Cynara