From: Lukasz Wojciechowski Date: Tue, 14 Oct 2014 07:21:41 +0000 (+0200) Subject: Clean up exception classes X-Git-Tag: submit/R4/20141115.054144~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c151752c38ea5572e4d2efbdc3ae55292ae8820;p=platform%2Fcore%2Fsecurity%2Fcynara.git Clean up exception classes 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 --- diff --git a/src/common/exceptions/BucketDeserializationException.h b/src/common/exceptions/BucketDeserializationException.h index c6b6f1d..c5670c8 100644 --- a/src/common/exceptions/BucketDeserializationException.h +++ b/src/common/exceptions/BucketDeserializationException.h @@ -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()) { diff --git a/src/common/exceptions/BucketNotExistsException.h b/src/common/exceptions/BucketNotExistsException.h index 7802210..9ba9505 100644 --- a/src/common/exceptions/BucketNotExistsException.h +++ b/src/common/exceptions/BucketNotExistsException.h @@ -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 */ diff --git a/src/common/exceptions/BucketRecordCorruptedException.h b/src/common/exceptions/BucketRecordCorruptedException.h index 4511fb5..92b29f7 100644 --- a/src/common/exceptions/BucketRecordCorruptedException.h +++ b/src/common/exceptions/BucketRecordCorruptedException.h @@ -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 */ diff --git a/src/common/exceptions/BucketSerializationException.h b/src/common/exceptions/BucketSerializationException.h index f6dba4c..1e02823 100644 --- a/src/common/exceptions/BucketSerializationException.h +++ b/src/common/exceptions/BucketSerializationException.h @@ -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()) { diff --git a/src/common/exceptions/CannotCreateFileException.h b/src/common/exceptions/CannotCreateFileException.h index 4195156..67c1d67 100644 --- a/src/common/exceptions/CannotCreateFileException.h +++ b/src/common/exceptions/CannotCreateFileException.h @@ -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()) { diff --git a/src/common/exceptions/DatabaseException.h b/src/common/exceptions/DatabaseException.h index 9cbd2b4..834d524 100644 --- a/src/common/exceptions/DatabaseException.h +++ b/src/common/exceptions/DatabaseException.h @@ -27,7 +27,8 @@ namespace Cynara { class DatabaseException : public Exception { - +public: + virtual ~DatabaseException() {}; }; } /* namespace Cynara */ diff --git a/src/common/exceptions/DefaultBucketDeletionException.h b/src/common/exceptions/DefaultBucketDeletionException.h index 9b75a00..a4742be 100644 --- a/src/common/exceptions/DefaultBucketDeletionException.h +++ b/src/common/exceptions/DefaultBucketDeletionException.h @@ -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"; diff --git a/src/common/exceptions/DefaultBucketSetNoneException.h b/src/common/exceptions/DefaultBucketSetNoneException.h index b7975cd..243c4d8 100644 --- a/src/common/exceptions/DefaultBucketSetNoneException.h +++ b/src/common/exceptions/DefaultBucketSetNoneException.h @@ -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"; diff --git a/src/common/exceptions/DescriptorNotExistsException.h b/src/common/exceptions/DescriptorNotExistsException.h index badb64a..3535b91 100644 --- a/src/common/exceptions/DescriptorNotExistsException.h +++ b/src/common/exceptions/DescriptorNotExistsException.h @@ -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 diff --git a/src/common/exceptions/Exception.h b/src/common/exceptions/Exception.h index 4f5f5eb..c5eb709 100644 --- a/src/common/exceptions/Exception.h +++ b/src/common/exceptions/Exception.h @@ -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(); } diff --git a/src/common/exceptions/FileNotFoundException.h b/src/common/exceptions/FileNotFoundException.h index e7aeead..4c446e2 100644 --- a/src/common/exceptions/FileNotFoundException.h +++ b/src/common/exceptions/FileNotFoundException.h @@ -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()) { diff --git a/src/common/exceptions/InitException.h b/src/common/exceptions/InitException.h index c93155c..cdb09a2 100644 --- a/src/common/exceptions/InitException.h +++ b/src/common/exceptions/InitException.h @@ -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"; diff --git a/src/common/exceptions/InvalidProtocolException.h b/src/common/exceptions/InvalidProtocolException.h index 89d0e4b..9b6a740 100644 --- a/src/common/exceptions/InvalidProtocolException.h +++ b/src/common/exceptions/InvalidProtocolException.h @@ -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 diff --git a/src/common/exceptions/NoMemoryException.h b/src/common/exceptions/NoMemoryException.h index d8a6086..2eca090 100644 --- a/src/common/exceptions/NoMemoryException.h +++ b/src/common/exceptions/NoMemoryException.h @@ -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; diff --git a/src/common/exceptions/NotImplementedException.h b/src/common/exceptions/NotImplementedException.h index 1496fd7..8ca3762 100644 --- a/src/common/exceptions/NotImplementedException.h +++ b/src/common/exceptions/NotImplementedException.h @@ -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"; diff --git a/src/common/exceptions/NullPointerException.h b/src/common/exceptions/NullPointerException.h index 47e4239..e735555 100644 --- a/src/common/exceptions/NullPointerException.h +++ b/src/common/exceptions/NullPointerException.h @@ -17,7 +17,7 @@ * @file src/common/exceptions/NullPointerException.h * @author Lukasz Wojciechowski * @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 diff --git a/src/common/exceptions/OutOfDataException.h b/src/common/exceptions/OutOfDataException.h index 716df13..6420819 100644 --- a/src/common/exceptions/OutOfDataException.h +++ b/src/common/exceptions/OutOfDataException.h @@ -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 diff --git a/src/common/exceptions/PluginNotFoundException.h b/src/common/exceptions/PluginNotFoundException.h index 3604075..4492a53 100644 --- a/src/common/exceptions/PluginNotFoundException.h +++ b/src/common/exceptions/PluginNotFoundException.h @@ -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 diff --git a/src/common/exceptions/UnexpectedErrorException.h b/src/common/exceptions/UnexpectedErrorException.h index ed0b72c..3080c0f 100644 --- a/src/common/exceptions/UnexpectedErrorException.h +++ b/src/common/exceptions/UnexpectedErrorException.h @@ -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