From 11018952e9bbd8a7c1cc25d49788a502d2897182 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 15 Jul 2016 13:52:45 -0700 Subject: [PATCH] Change API misuse exceptions in object_accessor.hpp to derive from `std::logic_error` rather than `std::runtime_error`. Also includes the following minor changes: * Renames `ReadOnlyPropertyValueException` to `ReadOnlyPropertyException` since it's the property that's read-only, not the value. * Elminiates some unnecessary copies of arguments passed to the exception constructors. * Makes the exception type data members public, since otherwise there's no point in storing them at. --- src/object-store/src/object_accessor.hpp | 47 ++++++++++-------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/object-store/src/object_accessor.hpp b/src/object-store/src/object_accessor.hpp index 226be5df..a19608a6 100644 --- a/src/object-store/src/object_accessor.hpp +++ b/src/object-store/src/object_accessor.hpp @@ -123,50 +123,43 @@ namespace realm { // // Deprecated // - static Mixed to_mixed(ContextType, ValueType&) { throw std::runtime_error("'Any' type is unsupported"); } + static Mixed to_mixed(ContextType, ValueType&) { throw std::logic_error("'Any' type is unsupported"); } }; - class InvalidatedObjectException : public std::runtime_error - { - public: - InvalidatedObjectException(const std::string object_type, const std::string message) : std::runtime_error(message), object_type(object_type) {} + struct InvalidatedObjectException : public std::logic_error { + InvalidatedObjectException(const std::string& object_type, const std::string& message) : + std::logic_error(message), object_type(object_type) {} const std::string object_type; }; - class InvalidPropertyException : public std::runtime_error - { - public: - InvalidPropertyException(const std::string object_type, const std::string property_name, const std::string message) : std::runtime_error(message), object_type(object_type), property_name(property_name) {} + struct InvalidPropertyException : public std::logic_error { + InvalidPropertyException(const std::string& object_type, const std::string& property_name, const std::string& message) : + std::logic_error(message), object_type(object_type), property_name(property_name) {} const std::string object_type; const std::string property_name; }; - class MissingPropertyValueException : public std::runtime_error - { - public: - MissingPropertyValueException(const std::string object_type, const std::string property_name, const std::string message) : std::runtime_error(message), object_type(object_type), property_name(property_name) {} + struct MissingPropertyValueException : public std::logic_error { + MissingPropertyValueException(const std::string& object_type, const std::string& property_name, const std::string& message) : + std::logic_error(message), object_type(object_type), property_name(property_name) {} const std::string object_type; const std::string property_name; }; - class MissingPrimaryKeyException : public std::runtime_error - { - public: - MissingPrimaryKeyException(const std::string object_type, const std::string message) : std::runtime_error(message), object_type(object_type) {} + struct MissingPrimaryKeyException : public std::logic_error { + MissingPrimaryKeyException(const std::string& object_type, const std::string& message) : std::logic_error(message), object_type(object_type) {} const std::string object_type; }; - class ReadOnlyPropertyValueException : public std::runtime_error { - public: - ReadOnlyPropertyValueException(const std::string& object_type, const std::string& property_name, const std::string& message) - : std::runtime_error(message), object_type(object_type), property_name(property_name) {} + struct ReadOnlyPropertyException : public std::logic_error { + ReadOnlyPropertyException(const std::string& object_type, const std::string& property_name, const std::string& message) : + std::logic_error(message), object_type(object_type), property_name(property_name) {} const std::string object_type; const std::string property_name; }; - class MutationOutsideTransactionException : public std::runtime_error { - public: - MutationOutsideTransactionException(std::string message) : std::runtime_error(message) {} + struct MutationOutsideTransactionException : public std::logic_error { + MutationOutsideTransactionException(const std::string& message) : std::logic_error(message) {} }; // @@ -265,9 +258,9 @@ namespace realm { break; } case PropertyType::LinkingObjects: - throw ReadOnlyPropertyValueException(m_object_schema->name, property.name, - util::format("Cannot modify read-only property '%1.%2'", - m_object_schema->name, property.name)); + throw ReadOnlyPropertyException(m_object_schema->name, property.name, + util::format("Cannot modify read-only property '%1.%2'", + m_object_schema->name, property.name)); } }