lmdbal/src/exceptions.h

104 lines
2.5 KiB
C++

/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_EXCEPTIONS_H
#define LMDBAL_EXCEPTIONS_H
#include <stdexcept>
#include <string>
#include <optional>
namespace LMDBAL {
class Exception : public std::exception {
public:
Exception();
virtual ~Exception();
virtual std::string getMessage() const = 0;
const char* what() const noexcept( true );
};
class Directory: public Exception {
public:
Directory(const std::string& path);
std::string getMessage() const;
private:
std::string path;
};
class Closed : public Exception {
public:
Closed(const std::string& p_operation, const std::string& dbName, const std::optional<std::string>& tableName = std::nullopt);
std::string getMessage() const;
private:
std::string operation;
std::string dbName;
std::optional<std::string> tableName;
};
class Opened : Exception {
public:
Opened(const std::string& dbName, const std::string& action);
std::string getMessage() const;
private:
std::string dbName;
std::string action;
};
class NotFound : public Exception {
public:
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;
};
class Exist : public Exception {
public:
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;
};
class Unknown : public Exception {
public:
Unknown(const std::string& dbName, const std::string& message, const std::optional<std::string>& tableName = std::nullopt);
std::string getMessage() const;
private:
std::string dbName;
std::optional<std::string> tableName;
std::string msg;
};
}
#endif //LMDBAL_EXCEPTIONS_H