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.
This commit is contained in:
Mark Rowe 2016-07-15 13:52:45 -07:00 committed by Thomas Goyne
parent 00e4790353
commit 11018952e9

View File

@ -123,50 +123,43 @@ namespace realm {
// //
// Deprecated // 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 struct InvalidatedObjectException : public std::logic_error {
{ InvalidatedObjectException(const std::string& object_type, const std::string& message) :
public: std::logic_error(message), object_type(object_type) {}
InvalidatedObjectException(const std::string object_type, const std::string message) : std::runtime_error(message), object_type(object_type) {}
const std::string object_type; const std::string object_type;
}; };
class InvalidPropertyException : public std::runtime_error struct InvalidPropertyException : public std::logic_error {
{ InvalidPropertyException(const std::string& object_type, const std::string& property_name, const std::string& message) :
public: std::logic_error(message), object_type(object_type), property_name(property_name) {}
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) {}
const std::string object_type; const std::string object_type;
const std::string property_name; const std::string property_name;
}; };
class MissingPropertyValueException : public std::runtime_error struct MissingPropertyValueException : public std::logic_error {
{ MissingPropertyValueException(const std::string& object_type, const std::string& property_name, const std::string& message) :
public: std::logic_error(message), object_type(object_type), property_name(property_name) {}
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) {}
const std::string object_type; const std::string object_type;
const std::string property_name; const std::string property_name;
}; };
class MissingPrimaryKeyException : public std::runtime_error struct MissingPrimaryKeyException : public std::logic_error {
{ MissingPrimaryKeyException(const std::string& object_type, const std::string& message) : std::logic_error(message), object_type(object_type) {}
public:
MissingPrimaryKeyException(const std::string object_type, const std::string message) : std::runtime_error(message), object_type(object_type) {}
const std::string object_type; const std::string object_type;
}; };
class ReadOnlyPropertyValueException : public std::runtime_error { struct ReadOnlyPropertyException : public std::logic_error {
public: ReadOnlyPropertyException(const std::string& object_type, const std::string& property_name, const std::string& message) :
ReadOnlyPropertyValueException(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) {}
: std::runtime_error(message), object_type(object_type), property_name(property_name) {}
const std::string object_type; const std::string object_type;
const std::string property_name; const std::string property_name;
}; };
class MutationOutsideTransactionException : public std::runtime_error { struct MutationOutsideTransactionException : public std::logic_error {
public: MutationOutsideTransactionException(const std::string& message) : std::logic_error(message) {}
MutationOutsideTransactionException(std::string message) : std::runtime_error(message) {}
}; };
// //
@ -265,9 +258,9 @@ namespace realm {
break; break;
} }
case PropertyType::LinkingObjects: case PropertyType::LinkingObjects:
throw ReadOnlyPropertyValueException(m_object_schema->name, property.name, throw ReadOnlyPropertyException(m_object_schema->name, property.name,
util::format("Cannot modify read-only property '%1.%2'", util::format("Cannot modify read-only property '%1.%2'",
m_object_schema->name, property.name)); m_object_schema->name, property.name));
} }
} }