2022-11-29 00:06:35 -03:00
|
|
|
#ifndef OBELISK_MODELS_ERROR_H
|
|
|
|
#define OBELISK_MODELS_ERROR_H
|
|
|
|
|
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace obelisk
|
|
|
|
{
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown by database models.
|
|
|
|
*
|
|
|
|
*/
|
2022-11-29 00:06:35 -03:00
|
|
|
class DatabaseException : public std::exception
|
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
protected:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief The error message describing the exception.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
std::string errorMessage_;
|
2022-11-29 00:06:35 -03:00
|
|
|
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-11-29 00:06:35 -03:00
|
|
|
DatabaseException() :
|
|
|
|
errorMessage_("an unknown error ocurred")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseException object.
|
|
|
|
*
|
|
|
|
* @param[in] errorCode The error code that came from sqlite.
|
|
|
|
*/
|
2022-11-29 00:06:35 -03:00
|
|
|
DatabaseException(const int errorCode) :
|
2022-12-13 17:35:14 -03:00
|
|
|
errorMessage_("database error " + std::to_string(errorCode) + " ocurred")
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseException object.
|
|
|
|
*
|
|
|
|
* @param[in] errorMessage The error message to describe the
|
|
|
|
* exception.
|
|
|
|
*/
|
2022-11-29 00:06:35 -03:00
|
|
|
DatabaseException(const std::string& errorMessage) :
|
|
|
|
errorMessage_(errorMessage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Retreive the exception message as a C type string.
|
|
|
|
*
|
|
|
|
* @return const char* The error message.
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
virtual const char* what() const noexcept
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
|
|
|
return errorMessage_.c_str();
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Set the error message.
|
|
|
|
*
|
|
|
|
* @param[in] errorMessage The error message.
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
virtual void setErrorMessage(const std::string errorMessage)
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
errorMessage_ = errorMessage;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if the string or blob size exceeds sqlite's
|
|
|
|
* limits.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseSizeException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseSizeException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseSizeException()
|
|
|
|
{
|
|
|
|
setErrorMessage("size of string or blob exceeds limits");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if the index used it out of range.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseRangeException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseRangeException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseRangeException()
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
setErrorMessage("parameter index is out of range");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if there is not enough memory to perform the
|
|
|
|
* operation.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseMemoryException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseMemoryException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseMemoryException()
|
|
|
|
{
|
|
|
|
setErrorMessage("not enough memory for operation");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if the database was busy.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseBusyException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseBusyException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseBusyException()
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-13 17:35:14 -03:00
|
|
|
setErrorMessage("database was busy and operation was not performed");
|
2022-12-10 21:11:39 -03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if there is a misuse of the databse.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseMisuseException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseMisuseException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseMisuseException()
|
|
|
|
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
setErrorMessage("misuse of the database routine");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Exception thrown if a constraint was violated.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
class DatabaseConstraintException : public obelisk::DatabaseException
|
|
|
|
{
|
|
|
|
public:
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseConstraintException object.
|
|
|
|
*
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseConstraintException()
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
setErrorMessage("a constraint exception occurred");
|
|
|
|
}
|
|
|
|
|
2023-02-18 21:06:42 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new DatabaseConstraintException object.
|
|
|
|
*
|
|
|
|
* @param[in] errorMessage The error message to send when the
|
|
|
|
* constraint is violated.
|
|
|
|
*/
|
2022-12-10 21:11:39 -03:00
|
|
|
DatabaseConstraintException(const std::string& errorMessage)
|
2022-11-29 00:06:35 -03:00
|
|
|
{
|
2022-12-10 21:11:39 -03:00
|
|
|
setErrorMessage(errorMessage);
|
|
|
|
}
|
2022-11-29 00:06:35 -03:00
|
|
|
};
|
|
|
|
} // namespace obelisk
|
|
|
|
|
|
|
|
#endif
|