forked from blue/lmdbal
some thoughts about exceptions
This commit is contained in:
parent
c3139974f1
commit
c491793387
9 changed files with 276 additions and 59 deletions
60
exceptions.h
60
exceptions.h
|
@ -24,82 +24,64 @@ namespace Core {
|
|||
|
||||
class DataBase::Directory: public Utils::Exception {
|
||||
public:
|
||||
Directory(const std::string& p_path):Exception(), path(p_path){}
|
||||
Directory(const std::string& path);
|
||||
|
||||
std::string getMessage() const{return "Can't create directory for database at " + path;}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class DataBase::Closed : public Utils::Exception {
|
||||
public:
|
||||
Closed(const std::string& op, const std::string& acc):Exception(), operation(op), account(acc){}
|
||||
Closed(const std::string& p_operation, const std::string& dbName, const std::string& tableName);
|
||||
|
||||
std::string getMessage() const{return "An attempt to perform operation " + operation + " on closed archive for " + account;}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string operation;
|
||||
std::string account;
|
||||
std::string dbName;
|
||||
std::string tableName;
|
||||
};
|
||||
|
||||
class DataBase::Opened : public Utils::Exception {
|
||||
public:
|
||||
Opened(const std::string& tn):Exception(), tableName(tn){}
|
||||
Opened(const std::string& dbName, const std::string& tableName);
|
||||
|
||||
std::string getMessage() const{return "An attempt to add table " + tableName + " but it's impossible to do if the DataBase is already opened";}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string dbName;
|
||||
std::string tableName;
|
||||
};
|
||||
|
||||
class DataBase::NotFound : public Utils::Exception {
|
||||
public:
|
||||
NotFound(const std::string& k, const std::string& acc):Exception(), key(k), account(acc){}
|
||||
NotFound(const std::string& key, const std::string& dbName, const std::string& tableName);
|
||||
|
||||
std::string getMessage() const{return "Element for id " + key + " wasn't found in database " + account;}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string key;
|
||||
std::string account;
|
||||
};
|
||||
|
||||
class DataBase::Empty : public Utils::Exception {
|
||||
public:
|
||||
Empty(const std::string& acc):Exception(), account(acc){}
|
||||
|
||||
std::string getMessage() const{return "An attempt to read ordered elements from database " + account + " but it's empty";}
|
||||
private:
|
||||
std::string account;
|
||||
std::string dbName;
|
||||
std::string tableName;
|
||||
};
|
||||
|
||||
class DataBase::Exist : public Utils::Exception {
|
||||
public:
|
||||
Exist(const std::string& acc, const std::string& p_key):Exception(), account(acc), key(p_key){}
|
||||
Exist(const std::string& key, const std::string& dbName, const std::string& tableName);
|
||||
|
||||
std::string getMessage() const{return "An attempt to insert element " + key + " to database " + account + " but it already has an element with given id";}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string account;
|
||||
std::string key;
|
||||
};
|
||||
|
||||
class DataBase::NoAvatar : public Utils::Exception {
|
||||
public:
|
||||
NoAvatar(const std::string& el, const std::string& res):Exception(), element(el), resource(res){
|
||||
if (resource.size() == 0) {
|
||||
resource = "for himself";
|
||||
}
|
||||
}
|
||||
|
||||
std::string getMessage() const{return "Element " + element + " has no avatar for " + resource ;}
|
||||
private:
|
||||
std::string element;
|
||||
std::string resource;
|
||||
std::string dbName;
|
||||
std::string tableName;
|
||||
};
|
||||
|
||||
class DataBase::Unknown : public Utils::Exception {
|
||||
public:
|
||||
Unknown(const std::string& acc, const std::string& message):Exception(), account(acc), msg(message){}
|
||||
Unknown(const std::string& dbName, const std::string& message, const std::optional<std::string>& tableName = std::nullopt);
|
||||
|
||||
std::string getMessage() const{return "Unknown error on database " + account + ": " + msg;}
|
||||
std::string getMessage() const;
|
||||
private:
|
||||
std::string account;
|
||||
std::string dbName;
|
||||
std::optional<std::string> tableName;
|
||||
std::string msg;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue