Unify custom exceptions

This commit is contained in:
Vladimir Golovnev (Glassez)
2021-05-05 16:41:30 +03:00
parent 89cedd411e
commit 9565b695ef
13 changed files with 43 additions and 57 deletions

View File

@@ -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;
}