/* * LMDB Abstraction Layer. * Copyright (C) 2023 Yury Gubich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef LMDBAL_EXCEPTIONS_H #define LMDBAL_EXCEPTIONS_H #include #include #include namespace LMDBAL { /** * \brief Parent abstract class for all LMDBAL exceptions */ class Exception : public std::exception { public: Exception(); virtual ~Exception(); virtual std::string getMessage() const = 0; /**<\brief returns exception message*/ const char* what() const noexcept( true ) override; }; /** * \brief Thrown if LMDBAL had issues creating or opening database directory */ class Directory: public Exception { public: /** * \brief Creates exception * * \param path - path of the directory that was supposed to be used to store the database */ Directory(const std::string& path); std::string getMessage() const; private: std::string path; }; /** * \brief Thrown if something in the database was called on closed state and it is not supported */ class Closed : public Exception { public: /** * \brief Creates exception * * \param operation - text name of the method that was called on closed database * \param dbName - name of the database * \param tableName - name of the storage which called that method, abscent if it's untracable or if it's thrown by the database */ Closed(const std::string& operation, const std::string& dbName, const std::optional& tableName = std::nullopt); std::string getMessage() const; private: std::string operation; std::string dbName; std::optional tableName; }; /** * \brief Thrown if something in the database was called on opened state and it is not supported */ class Opened : Exception { public: /** * \brief Creates exception * * \param action - text name of the method that was called on opened database * \param dbName - name of the database */ Opened(const std::string& dbName, const std::string& action); std::string getMessage() const; private: std::string dbName; std::string action; }; /** * \brief Thrown if something in the database was not found */ class NotFound : public Exception { public: /** * \brief Creates exception * * \param key - record key that was not found * \param dbName - name of the database * \param tableName - name of the storage that was looked for a record */ NotFound(const std::string& key, const std::string& dbName, const std::string& tableName); std::string getMessage() const; private: std::string key; std::string dbName; std::string tableName; }; /** * \brief Thrown if there was attempt to define storages with conflicting names */ class StorageDuplicate : public Exception { public: /** * \brief Creates exception * * \param dbName - name of the database * \param tableName - that name that was conflicting */ StorageDuplicate(const std::string& dbName, const std::string& tableName); std::string getMessage() const; private: std::string dbName; std::string tableName; }; /** * \brief Thrown if there was a key conflict in one of the storages */ class Exist : public Exception { public: /** * \brief Creates exception * * \param key - record key that caused the conflict * \param dbName - name of the database * \param tableName - name of the storage that was operated with */ Exist(const std::string& key, const std::string& dbName, const std::string& tableName); std::string getMessage() const; private: std::string key; std::string dbName; std::string tableName; }; /** * \brief Thrown if something unexpected happened */ class Unknown : public Exception { public: /** * \brief Creates exception * * \param message - text description of the error, most of the times contains the result of mdb_strerror * \param dbName - name of the database * \param tableName - name of the storage that was operated with, abscent if the operation was with the database itself */ Unknown(const std::string& dbName, const std::string& message, const std::optional& tableName = std::nullopt); std::string getMessage() const; private: std::string dbName; std::optional tableName; std::string msg; }; } #endif //LMDBAL_EXCEPTIONS_H