mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 15:04:36 +00:00
Unify custom exceptions
This commit is contained in:
parent
89cedd411e
commit
9565b695ef
@ -638,7 +638,7 @@ int Application::exec(const QStringList ¶ms)
|
||||
catch (const RuntimeError &err)
|
||||
{
|
||||
#ifdef DISABLE_GUI
|
||||
fprintf(stderr, "%s", err.what());
|
||||
fprintf(stderr, "%s", qPrintable(err.message()));
|
||||
#else
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
|
@ -498,17 +498,6 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
|
||||
return result;
|
||||
}
|
||||
|
||||
CommandLineParameterError::CommandLineParameterError(const QString &messageForUser)
|
||||
: std::runtime_error(messageForUser.toLocal8Bit().data())
|
||||
, m_messageForUser(messageForUser)
|
||||
{
|
||||
}
|
||||
|
||||
const QString &CommandLineParameterError::messageForUser() const
|
||||
{
|
||||
return m_messageForUser;
|
||||
}
|
||||
|
||||
QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN, int wrapAtColumn = WRAP_AT_COLUMN)
|
||||
{
|
||||
QStringList words = text.split(' ');
|
||||
|
@ -31,11 +31,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "base/exceptions.h"
|
||||
|
||||
class QProcessEnvironment;
|
||||
|
||||
struct QBtCommandLineParameters
|
||||
@ -67,14 +68,10 @@ struct QBtCommandLineParameters
|
||||
QStringList paramList() const;
|
||||
};
|
||||
|
||||
class CommandLineParameterError : public std::runtime_error
|
||||
class CommandLineParameterError : public RuntimeError
|
||||
{
|
||||
public:
|
||||
explicit CommandLineParameterError(const QString &messageForUser);
|
||||
const QString &messageForUser() const;
|
||||
|
||||
private:
|
||||
const QString m_messageForUser;
|
||||
using RuntimeError::RuntimeError;
|
||||
};
|
||||
|
||||
QBtCommandLineParameters parseCommandLine(const QStringList &args);
|
||||
|
@ -311,7 +311,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
catch (const CommandLineParameterError &er)
|
||||
{
|
||||
displayBadArgMessage(er.messageForUser());
|
||||
displayBadArgMessage(er.message());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ Http::Response Tracker::processRequest(const Http::Request &request, const Http:
|
||||
|
||||
const lt::entry::dictionary_type bencodedEntry =
|
||||
{
|
||||
{ANNOUNCE_RESPONSE_FAILURE_REASON, {error.what()}}
|
||||
{ANNOUNCE_RESPONSE_FAILURE_REASON, {error.message().toStdString()}}
|
||||
};
|
||||
QByteArray reply;
|
||||
lt::bencode(std::back_inserter(reply), bencodedEntry);
|
||||
|
@ -28,12 +28,12 @@
|
||||
|
||||
#include "exceptions.h"
|
||||
|
||||
RuntimeError::RuntimeError(const QString &message)
|
||||
: std::runtime_error {message.toUtf8().data()}
|
||||
Exception::Exception(const QString &message) noexcept
|
||||
: m_message {message}
|
||||
{
|
||||
}
|
||||
|
||||
QString RuntimeError::message() const
|
||||
QString Exception::message() const noexcept
|
||||
{
|
||||
return what();
|
||||
return m_message;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2018 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2018, 2021 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -28,12 +28,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <QString>
|
||||
|
||||
class RuntimeError : public std::runtime_error
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
explicit RuntimeError(const QString &message = {});
|
||||
QString message() const;
|
||||
explicit Exception(const QString &message = {}) noexcept;
|
||||
[[nodiscard]] QString message() const noexcept;
|
||||
|
||||
private:
|
||||
QString m_message;
|
||||
};
|
||||
|
||||
class RuntimeError : public Exception
|
||||
{
|
||||
public:
|
||||
using Exception::Exception;
|
||||
};
|
||||
|
@ -114,7 +114,7 @@ AutoDownloader::AutoDownloader()
|
||||
m_fileStorage = new AsyncFileStorage(
|
||||
Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Config) + ConfFolderName));
|
||||
if (!m_fileStorage)
|
||||
throw std::runtime_error("Directory for RSS AutoDownloader data is unavailable.");
|
||||
throw RuntimeError(tr("Directory for RSS AutoDownloader data is unavailable."));
|
||||
|
||||
m_fileStorage->moveToThread(m_ioThread);
|
||||
connect(m_ioThread, &QThread::finished, m_fileStorage, &AsyncFileStorage::deleteLater);
|
||||
@ -527,13 +527,3 @@ void AutoDownloader::timerEvent(QTimerEvent *event)
|
||||
Q_UNUSED(event);
|
||||
store();
|
||||
}
|
||||
|
||||
ParsingError::ParsingError(const QString &message)
|
||||
: std::runtime_error(message.toUtf8().data())
|
||||
{
|
||||
}
|
||||
|
||||
QString ParsingError::message() const
|
||||
{
|
||||
return what();
|
||||
}
|
||||
|
@ -28,8 +28,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QBasicTimer>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
@ -38,6 +36,8 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "base/exceptions.h"
|
||||
|
||||
class QThread;
|
||||
class QTimer;
|
||||
|
||||
@ -53,11 +53,10 @@ namespace RSS
|
||||
|
||||
class AutoDownloadRule;
|
||||
|
||||
class ParsingError : public std::runtime_error
|
||||
class ParsingError : public RuntimeError
|
||||
{
|
||||
public:
|
||||
explicit ParsingError(const QString &message);
|
||||
QString message() const;
|
||||
using RuntimeError::RuntimeError;
|
||||
};
|
||||
|
||||
class AutoDownloader final : public QObject
|
||||
|
@ -313,7 +313,7 @@ void Feed::loadArticles(const QByteArray &data)
|
||||
if (!addArticle(article))
|
||||
delete article;
|
||||
}
|
||||
catch (const std::runtime_error&) {}
|
||||
catch (const RuntimeError &) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ void Feed::loadArticlesLegacy()
|
||||
if (!addArticle(article))
|
||||
delete article;
|
||||
}
|
||||
catch (const std::runtime_error&) {}
|
||||
catch (const RuntimeError &) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace
|
||||
{
|
||||
info = {exeName, versionStr.left(idx)};
|
||||
}
|
||||
catch (const std::runtime_error &)
|
||||
catch (const RuntimeError &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -29,11 +29,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
#include "base/exceptions.h"
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
template <typename T, std::size_t N, std::size_t Mandatory = N>
|
||||
@ -64,7 +65,7 @@ namespace Utils
|
||||
* @brief Creates version from string in format "x.y.z"
|
||||
*
|
||||
* @param version Version string in format "x.y.z"
|
||||
* @throws std::runtime_error if parsing fails
|
||||
* @throws RuntimeError if parsing fails
|
||||
*/
|
||||
Version(const QString &version)
|
||||
: Version {version.split(QLatin1Char('.'))}
|
||||
@ -75,7 +76,7 @@ namespace Utils
|
||||
* @brief Creates version from byte array in format "x.y.z"
|
||||
*
|
||||
* @param version Version string in format "x.y.z"
|
||||
* @throws std::runtime_error if parsing fails
|
||||
* @throws RuntimeError if parsing fails
|
||||
*/
|
||||
Version(const QByteArray &version)
|
||||
: Version {version.split('.')}
|
||||
@ -150,9 +151,9 @@ namespace Utils
|
||||
{
|
||||
return Version(s);
|
||||
}
|
||||
catch (const std::runtime_error &er)
|
||||
catch (const RuntimeError &er)
|
||||
{
|
||||
qDebug() << "Error parsing version:" << er.what();
|
||||
qDebug() << "Error parsing version:" << er.message();
|
||||
return defaultVersion;
|
||||
}
|
||||
}
|
||||
@ -165,7 +166,9 @@ namespace Utils
|
||||
{
|
||||
if ((static_cast<std::size_t>(versionParts.size()) > N)
|
||||
|| (static_cast<std::size_t>(versionParts.size()) < Mandatory))
|
||||
throw std::runtime_error("Incorrect number of version components");
|
||||
{
|
||||
throw RuntimeError(QLatin1String("Incorrect number of version components"));
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
ComponentsArray res {{}};
|
||||
@ -173,7 +176,7 @@ namespace Utils
|
||||
{
|
||||
res[i] = static_cast<T>(versionParts[static_cast<typename StringsList::size_type>(i)].toInt(&ok));
|
||||
if (!ok)
|
||||
throw std::runtime_error("Can not parse version component");
|
||||
throw RuntimeError(QLatin1String("Can not parse version component"));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ namespace
|
||||
}
|
||||
return (newVersion > currentVersion);
|
||||
}
|
||||
catch (const std::runtime_error &)
|
||||
catch (const RuntimeError &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user