Changed exceptions to std bases
This commit is contained in:
@@ -19,36 +19,197 @@
|
||||
#ifndef EXCEPTIONS_H
|
||||
#define EXCEPTIONS_H
|
||||
#include <QString>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include "komplex_global.h"
|
||||
|
||||
struct KOMPLEX_EXPORT Exception : std::exception
|
||||
struct KOMPLEX_EXPORT network_exception : std::ios_base::failure
|
||||
{
|
||||
explicit Exception(const QString &message, quint16 errorCode = 0)
|
||||
: std::exception(), message(message), errorCode(errorCode){}
|
||||
network_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
const QString message;
|
||||
const quint16 errorCode;
|
||||
network_exception(const std::string &message, const std::error_code &code) :
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
network_exception(const QString &message, const QString &details, const std::error_code &code) :
|
||||
details(details.toStdString()),
|
||||
std::ios_base::failure(message.toStdString(), code) { }
|
||||
|
||||
network_exception(const QString &message, const int code = errno) :
|
||||
std::ios_base::failure
|
||||
(
|
||||
message.toStdString(),
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
const std::string details;
|
||||
};
|
||||
|
||||
struct KOMPLEX_EXPORT NetworkException : Exception
|
||||
struct KOMPLEX_EXPORT file_exception : std::filesystem::filesystem_error
|
||||
{
|
||||
NetworkException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {}
|
||||
file_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
std::filesystem::filesystem_error(message, code) { }
|
||||
|
||||
file_exception(const std::string &message, const std::error_code &code) :
|
||||
std::filesystem::filesystem_error(message, code) { }
|
||||
|
||||
file_exception(const std::string &message, const int code = errno) :
|
||||
std::filesystem::filesystem_error
|
||||
(
|
||||
message,
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
file_exception(const std::string &message, const std::string &details, const int code = errno) :
|
||||
details(details),
|
||||
std::filesystem::filesystem_error
|
||||
(
|
||||
message,
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
const std::string details;
|
||||
};
|
||||
struct KOMPLEX_EXPORT FileException : Exception
|
||||
|
||||
struct KOMPLEX_EXPORT sql_exception : std::ios_base::failure
|
||||
{
|
||||
FileException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {}
|
||||
sql_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
sql_exception(const std::string &message, const std::error_code &code) :
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
sql_exception(const std::string &message, const int code = errno) :
|
||||
std::ios_base::failure
|
||||
(
|
||||
message,
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
const std::string details;
|
||||
};
|
||||
struct KOMPLEX_EXPORT SqlException : Exception
|
||||
|
||||
struct KOMPLEX_EXPORT wallet_exception : std::ios_base::failure
|
||||
{
|
||||
SqlException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {}
|
||||
wallet_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
wallet_exception(const std::string &message, const std::error_code &code) :
|
||||
std::ios_base::failure(message, code) { }
|
||||
|
||||
wallet_exception(const std::string &message, const std::string &details, const int code = errno) :
|
||||
details(details),
|
||||
std::ios_base::failure
|
||||
(
|
||||
message,
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
wallet_exception(const std::string &message, const int code = errno) :
|
||||
std::ios_base::failure
|
||||
(
|
||||
message,
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
) { }
|
||||
|
||||
const std::string details;
|
||||
};
|
||||
struct KOMPLEX_EXPORT WalletException : Exception
|
||||
|
||||
struct KOMPLEX_EXPORT process_exception : std::runtime_error
|
||||
{
|
||||
WalletException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {}
|
||||
process_exception(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
code(code),
|
||||
std::runtime_error(message) { }
|
||||
|
||||
process_exception(const std::string &message, const std::error_code &code) :
|
||||
code(code),
|
||||
std::runtime_error(message) { }
|
||||
|
||||
process_exception(const std::string &message, const int code = errno) :
|
||||
code
|
||||
(
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
),
|
||||
std::runtime_error
|
||||
(
|
||||
message
|
||||
) { }
|
||||
|
||||
process_exception(const std::string &message, const std::string &details, const int code = errno) :
|
||||
details(details),
|
||||
code
|
||||
(
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
),
|
||||
std::runtime_error (message) { }
|
||||
|
||||
const std::string details;
|
||||
const std::error_code code;
|
||||
};
|
||||
struct KOMPLEX_EXPORT ShaderCompilerException : Exception
|
||||
|
||||
namespace shader
|
||||
{
|
||||
ShaderCompilerException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {}
|
||||
};
|
||||
struct KOMPLEX_EXPORT logic_error : std::logic_error
|
||||
{
|
||||
logic_error(const std::string &message, const std::string &details, const std::error_code &code) :
|
||||
details(details),
|
||||
code(code),
|
||||
std::logic_error(message) { }
|
||||
|
||||
logic_error(const std::string &message, const std::error_code &code) :
|
||||
code(code),
|
||||
std::logic_error(message) { }
|
||||
|
||||
logic_error(const std::string &message, const std::string &details = {}, const int code = errno) :
|
||||
code
|
||||
(
|
||||
std::error_code
|
||||
(
|
||||
code,
|
||||
std::system_category()
|
||||
)
|
||||
),
|
||||
std::logic_error(message) { }
|
||||
|
||||
const std::string details;
|
||||
const std::error_code code;
|
||||
};
|
||||
}
|
||||
#endif // EXCEPTIONS_H
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "qwallet.h"
|
||||
#include "../3rdparty/qtkeychain/qtkeychain/keychain.h"
|
||||
#include "common/exceptions.h"
|
||||
|
||||
auto QWallet::read(const QString &service, const QString &key) const -> QFuture<QByteArray>
|
||||
{
|
||||
@@ -29,7 +30,11 @@ auto QWallet::read(const QString &service, const QString &key) const -> QFuture<
|
||||
else
|
||||
{
|
||||
m_errorString = qPrintable(j->errorString());
|
||||
throw std::exception();
|
||||
throw wallet_exception
|
||||
(
|
||||
QStringLiteral("Wallet read error").toStdString(),
|
||||
errorString().toStdString()
|
||||
);
|
||||
}
|
||||
|
||||
loop.quit();
|
||||
@@ -65,11 +70,15 @@ auto QWallet::write(const QString &service, const QString &key, const QByteArray
|
||||
this,
|
||||
[this, key, &loop, &success](QKeychain::Job *job)
|
||||
{
|
||||
auto j = static_cast<QKeychain::ReadPasswordJob*>(job);
|
||||
auto j = static_cast<QKeychain::WritePasswordJob*>(job);
|
||||
if (j->error() != QKeychain::NoError)
|
||||
{
|
||||
setErrorString(qPrintable(j->errorString()));
|
||||
throw std::exception();
|
||||
throw wallet_exception
|
||||
(
|
||||
QStringLiteral("Wallet write error").toStdString(),
|
||||
errorString().toStdString()
|
||||
);
|
||||
}
|
||||
|
||||
loop.quit();
|
||||
@@ -102,7 +111,7 @@ auto QWallet::remove(const QString &service, const QString &key) -> QFuture<void
|
||||
this,
|
||||
[this, key, &loop, &value](QKeychain::Job *job)
|
||||
{
|
||||
auto j = static_cast<QKeychain::ReadPasswordJob*>(job);
|
||||
auto j = static_cast<QKeychain::DeletePasswordJob*>(job);
|
||||
if (j->error() != QKeychain::NoError)
|
||||
{
|
||||
m_errorString = qPrintable(j->errorString());
|
||||
|
||||
Reference in New Issue
Block a user