From 01ad95b6de627c0ca8296e5be8b9f89728af0aa7 Mon Sep 17 00:00:00 2001 From: coderhyme Date: Sat, 13 Jun 2015 13:59:58 +0900 Subject: [PATCH] Add exception descriptions to explain what error is Move two exceptions to another header which is more appropriate place to be defined. Change-Id: Ibbc2d0a057f97f285ebc17acf2abce6b67e22af7 Signed-off-by: coderhyme Reviewed-on: https://gerrit.iotivity.org/gerrit/1308 Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../primitiveResource/include/PrimitiveException.h | 21 +-------------------- .../primitiveResource/include/ResourceAttributes.h | 13 +++++++++++++ .../serverBuilder/include/PrimitiveServerResource.h | 4 ++++ .../serverBuilder/src/PrimitiveServerResource.cpp | 4 ++-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/service/basis/common/primitiveResource/include/PrimitiveException.h b/service/basis/common/primitiveResource/include/PrimitiveException.h index 73984c6..a4a8570 100755 --- a/service/basis/common/primitiveResource/include/PrimitiveException.h +++ b/service/basis/common/primitiveResource/include/PrimitiveException.h @@ -35,6 +35,7 @@ namespace OIC public: PrimitiveException() {} PrimitiveException(const std::string& what) : m_what{ what } {} + PrimitiveException(std::string&& what) : m_what{ std::move(what) } {} const char* what() const noexcept override { @@ -56,26 +57,6 @@ namespace OIC private: OCStackResult m_reason; }; - - - class BadGetException: public PrimitiveException - { - public: - BadGetException(const std::string& what) - { - - } - }; - - class InvalidKeyException: public PrimitiveException - { - public: - InvalidKeyException(const std::string& what) - { - - } - }; - } } diff --git a/service/basis/common/primitiveResource/include/ResourceAttributes.h b/service/basis/common/primitiveResource/include/ResourceAttributes.h index 297293d..33e7430 100755 --- a/service/basis/common/primitiveResource/include/ResourceAttributes.h +++ b/service/basis/common/primitiveResource/include/ResourceAttributes.h @@ -43,6 +43,19 @@ namespace OIC { namespace Service { + class BadGetException: public PrimitiveException + { + public: + BadGetException(const std::string& what) : PrimitiveException{ what } {} + BadGetException(std::string&& what) : PrimitiveException{ std::move(what) } {} + }; + + class InvalidKeyException: public PrimitiveException + { + public: + InvalidKeyException(const std::string& what) : PrimitiveException{ what } {} + InvalidKeyException(std::string&& what) : PrimitiveException{ std::move(what) } {} + }; class ResourceAttributes { diff --git a/service/basis/serverBuilder/include/PrimitiveServerResource.h b/service/basis/serverBuilder/include/PrimitiveServerResource.h index a4a8524..87e3a0d 100644 --- a/service/basis/serverBuilder/include/PrimitiveServerResource.h +++ b/service/basis/serverBuilder/include/PrimitiveServerResource.h @@ -42,10 +42,14 @@ namespace OIC class NoLockException: public PrimitiveException { + public: + NoLockException(std::string&& what) : PrimitiveException{ std::move(what) } {} }; class DeadLockException: public PrimitiveException { + public: + DeadLockException(std::string&& what) : PrimitiveException{ std::move(what) } {} }; class PrimitiveServerResource diff --git a/service/basis/serverBuilder/src/PrimitiveServerResource.cpp b/service/basis/serverBuilder/src/PrimitiveServerResource.cpp index 1c22d31..3fa0ae0 100644 --- a/service/basis/serverBuilder/src/PrimitiveServerResource.cpp +++ b/service/basis/serverBuilder/src/PrimitiveServerResource.cpp @@ -180,7 +180,7 @@ namespace OIC { if (m_lockOwner != std::this_thread::get_id()) { - throw NoLockException{ }; + throw NoLockException{ "Must acquire the lock first using LockGuard." }; } } @@ -287,7 +287,7 @@ namespace OIC { if (m_serverResource.m_lockOwner == std::this_thread::get_id()) { - throw DeadLockException{ }; + throw DeadLockException{ "Can't lock recursively in same thread." }; } m_serverResource.m_mutex.lock(); -- 2.7.4