Skip to content

Commit

Permalink
unified left exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jan 18, 2022
1 parent 71d22f2 commit f4106a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/orm/connectors/connectionfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ConnectionFactory::createConnector(const QVariantHash &config) const
{
// This method is public, so I left this check here
if (!config.contains(driver_))
throw std::domain_error("A 'driver' configuration parameter must be specified.");
throw Exceptions::RuntimeError(
"A 'driver' configuration parameter must be specified.");

const auto driver = config[driver_].value<QString>();

Expand All @@ -41,8 +42,8 @@ ConnectionFactory::createConnector(const QVariantHash &config) const
// if (driver == "SQLSRV")
// return std::make_unique<SqlServerConnector>();

throw std::domain_error(
"Unsupported driver '" + driver.toStdString() + "'.");
throw Exceptions::RuntimeError(QStringLiteral("Unsupported driver '%1'.")
.arg(driver));
}

QVariantHash &
Expand Down Expand Up @@ -155,15 +156,15 @@ ConnectionFactory::createConnection(
// return std::make_unique<SqlServerConnection>(std::move(connection), database,
// prefix, config);

throw std::domain_error(
"Unsupported driver '" + driver.toStdString() + "'.");
throw Exceptions::RuntimeError(QStringLiteral("Unsupported driver '%1'.")
.arg(driver));
}

QStringList ConnectionFactory::parseHosts(const QVariantHash &config) const
{
if (!config.contains(host_))
// TODO now unify exception, std::domain_error is for user code, create own exceptions and use InvalidArgumentError, or runtime/logic error silverqx
throw std::domain_error("Database 'host' configuration parameter is required.");
throw Exceptions::RuntimeError(
"Database 'host' configuration parameter is required.");

auto hosts = config[host_].value<QStringList>();

Expand All @@ -176,8 +177,9 @@ void ConnectionFactory::validateHosts(const QStringList &hosts) const
{
for (const auto &host : hosts)
if (host.isEmpty())
throw std::domain_error("Database 'host' configuration parameter "
"can not contain empty value.");
throw Exceptions::RuntimeError(
"Database 'host' configuration parameter can not contain empty "
"value.");
}

} // namespace Orm::Connectors
Expand Down
3 changes: 1 addition & 2 deletions src/orm/connectors/sqliteconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QtSql/QSqlQuery>

#include "orm/constants.hpp"
#include "orm/exceptions/invalidargumenterror.hpp"
#include "orm/exceptions/queryerror.hpp"
#include "orm/utils/type.hpp"

Expand Down Expand Up @@ -93,7 +92,7 @@ void SQLiteConnector::checkDatabaseExists(const QVariantHash &config) const
checkDatabaseExists = config[check_database_exists].value<bool>();

if (checkDatabaseExists && !QFile::exists(path))
throw Exceptions::InvalidArgumentError(
throw Exceptions::RuntimeError(
QStringLiteral("SQLite Database file '%1' does not exist.").arg(path));
}

Expand Down
1 change: 0 additions & 1 deletion src/orm/databaseconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ QSqlQuery DatabaseConnection::statement(const QString &queryString,
include the bindings with SQL, which will make this exception a lot
more helpful to the developer instead of just the database's errors. */
throw Exceptions::QueryError(
// TODO next use __tiny_func__ in similar statements/exceptions silverqx
QStringLiteral("Statement in %1() failed.").arg(functionName),
query, bindings_);
});
Expand Down

0 comments on commit f4106a8

Please sign in to comment.