diff --git a/src/knowledge_base.cpp b/src/knowledge_base.cpp index 2f1e82e..6a53f2e 100644 --- a/src/knowledge_base.cpp +++ b/src/knowledge_base.cpp @@ -93,7 +93,7 @@ void obelisk::KnowledgeBase::addEntities(std::vector& entities) { entity.insertEntity(dbConnection_); } - catch (obelisk::DatabaseException::ConstraintException& exception) + catch (obelisk::DatabaseConstraintException& exception) { // ignore unique constraint error if (std::strcmp(exception.what(), @@ -114,7 +114,7 @@ void obelisk::KnowledgeBase::addVerbs(std::vector& verbs) { verb.insertVerb(dbConnection_); } - catch (obelisk::DatabaseException::ConstraintException& exception) + catch (obelisk::DatabaseConstraintException& exception) { // ignore unique constraint error if (std::strcmp(exception.what(), @@ -135,7 +135,7 @@ void obelisk::KnowledgeBase::addFacts(std::vector& facts) { fact.insertFact(dbConnection_); } - catch (obelisk::DatabaseException::ConstraintException& exception) + catch (obelisk::DatabaseConstraintException& exception) { // ignore unique constraint error if (std::strcmp(exception.what(), diff --git a/src/models/entity.cpp b/src/models/entity.cpp index d7e81a8..159cf46 100644 --- a/src/models/entity.cpp +++ b/src/models/entity.cpp @@ -38,13 +38,13 @@ void obelisk::Entity::selectEntity(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -62,10 +62,10 @@ void obelisk::Entity::selectEntity(sqlite3* dbConnection) setName((char*) sqlite3_column_text(ppStmt, 1)); break; case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -106,13 +106,13 @@ void obelisk::Entity::insertEntity(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -127,13 +127,13 @@ void obelisk::Entity::insertEntity(sqlite3* dbConnection) sqlite3_set_last_insert_rowid(dbConnection, 0); break; case SQLITE_CONSTRAINT : - throw obelisk::DatabaseException::ConstraintException( + throw obelisk::DatabaseConstraintException( sqlite3_errmsg(dbConnection)); case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); diff --git a/src/models/error.h b/src/models/error.h index e8ace1b..7c733c2 100644 --- a/src/models/error.h +++ b/src/models/error.h @@ -8,8 +8,8 @@ namespace obelisk { class DatabaseException : public std::exception { - private: - const std::string errorMessage_; + protected: + std::string errorMessage_; public: DatabaseException() : @@ -28,118 +28,76 @@ namespace obelisk { } - const char* what() const noexcept + virtual const char* what() const noexcept { return errorMessage_.c_str(); } - class SizeException : public std::exception + virtual void setErrorMessage(const std::string errorMessage) { - private: - const std::string errorMessage_; + errorMessage_ = errorMessage; + } + }; - public: - SizeException() : - errorMessage_("size of string or blob exceeds limits") - { - } - - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; - - class RangeException : public std::exception + class DatabaseSizeException : public obelisk::DatabaseException + { + public: + DatabaseSizeException() { - private: - const std::string errorMessage_; + setErrorMessage("size of string or blob exceeds limits"); + } + }; - public: - RangeException() : - errorMessage_("parameter index is out of range") - { - } - - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; - - class MemoryException : public std::exception + class DatabaseRangeException : public obelisk::DatabaseException + { + public: + DatabaseRangeException() { - private: - const std::string errorMessage_; + setErrorMessage("parameter index is out of range"); + } + }; - public: - MemoryException() : - errorMessage_("not enough memory for operation") - { - } - - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; - - class BusyException : public std::exception + class DatabaseMemoryException : public obelisk::DatabaseException + { + public: + DatabaseMemoryException() { - private: - const std::string errorMessage_; + setErrorMessage("not enough memory for operation"); + } + }; - public: - BusyException() : - errorMessage_( - "database was busy and operation not performed") - { - } - - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; - - class MisuseException : public std::exception + class DatabaseBusyException : public obelisk::DatabaseException + { + public: + DatabaseBusyException() { - private: - const std::string errorMessage_; + setErrorMessage( + "database was busy and operation was not performed"); + } + }; - public: - MisuseException() : - errorMessage_("misuse of the database routine") - { - } + class DatabaseMisuseException : public obelisk::DatabaseException + { + public: + DatabaseMisuseException() - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; - - class ConstraintException : public std::exception { - private: - const std::string errorMessage_; + setErrorMessage("misuse of the database routine"); + } + }; - public: - ConstraintException() : - errorMessage_("a constraint exception occurred") - { - } + class DatabaseConstraintException : public obelisk::DatabaseException + { + public: + DatabaseConstraintException() + { + setErrorMessage("a constraint exception occurred"); + } - ConstraintException(const std::string& errorMessage) : - errorMessage_(errorMessage) - { - } - - const char* what() const noexcept - { - return errorMessage_.c_str(); - } - }; + DatabaseConstraintException(const std::string& errorMessage) + { + setErrorMessage(errorMessage); + } }; } // namespace obelisk diff --git a/src/models/fact.cpp b/src/models/fact.cpp index 467373d..75f0058 100644 --- a/src/models/fact.cpp +++ b/src/models/fact.cpp @@ -43,13 +43,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -62,13 +62,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -81,13 +81,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -107,10 +107,10 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection) getVerb().setId(sqlite3_column_int(ppStmt, 3)); break; case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -149,13 +149,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -168,13 +168,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -187,13 +187,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -208,13 +208,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection) sqlite3_set_last_insert_rowid(dbConnection, 0); break; case SQLITE_CONSTRAINT : - throw obelisk::DatabaseException::ConstraintException( + throw obelisk::DatabaseConstraintException( sqlite3_errmsg(dbConnection)); case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); diff --git a/src/models/verb.cpp b/src/models/verb.cpp index 9649533..778d89a 100644 --- a/src/models/verb.cpp +++ b/src/models/verb.cpp @@ -39,13 +39,13 @@ void obelisk::Verb::selectVerb(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -63,10 +63,10 @@ void obelisk::Verb::selectVerb(sqlite3* dbConnection) setName((char*) sqlite3_column_text(ppStmt, 1)); break; case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -106,13 +106,13 @@ void obelisk::Verb::insertVerb(sqlite3* dbConnection) case SQLITE_OK : break; case SQLITE_TOOBIG : - throw obelisk::DatabaseException::SizeException(); + throw obelisk::DatabaseSizeException(); break; case SQLITE_RANGE : - throw obelisk::DatabaseException::RangeException(); + throw obelisk::DatabaseRangeException(); break; case SQLITE_NOMEM : - throw obelisk::DatabaseException::MemoryException(); + throw obelisk::DatabaseMemoryException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); @@ -127,13 +127,13 @@ void obelisk::Verb::insertVerb(sqlite3* dbConnection) sqlite3_set_last_insert_rowid(dbConnection, 0); break; case SQLITE_CONSTRAINT : - throw obelisk::DatabaseException::ConstraintException( + throw obelisk::DatabaseConstraintException( sqlite3_errmsg(dbConnection)); case SQLITE_BUSY : - throw obelisk::DatabaseException::BusyException(); + throw obelisk::DatabaseBusyException(); break; case SQLITE_MISUSE : - throw obelisk::DatabaseException::MisuseException(); + throw obelisk::DatabaseMisuseException(); break; default : throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));