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:
parent
00e4790353
commit
11018952e9
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue