Mercurial > dedupe
changeset 32:c978d4a6514d
Replace unnecessary asserts with exceptions.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 06 Sep 2012 19:22:32 +0200 |
| parents | bf3dce7fedcb |
| children | 44a3c32dd0cb |
| files | DBCache.hpp SqliteDBLink.cpp |
| diffstat | 2 files changed, 6 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/DBCache.hpp Thu Sep 06 19:14:58 2012 +0200 +++ b/DBCache.hpp Thu Sep 06 19:22:32 2012 +0200 @@ -9,7 +9,6 @@ #include <QtCore/QStringList> #include <QtCore/QVariant> -#include <cassert> #include "OrderedPair.hpp" #include <boost/optional.hpp> @@ -17,6 +16,7 @@ #include "ThreadSafeLookup.hpp" #include "UniqueString.hpp" #include "Exception/SQLException.hpp" +#include "Exception/IOException.hpp" template<typename T> @@ -301,8 +301,8 @@ { db = QSqlDatabase::addDatabase("QSQLITE", "dictName"); db.setDatabaseName(dbName); - bool ok = db.open(); - assert(ok); + if (!db.open()) + throw IOException(QString("Unable to open SQLite database with path '%1'").arg(dictName)); setup(db, dictName); }
--- a/SqliteDBLink.cpp Thu Sep 06 19:14:58 2012 +0200 +++ b/SqliteDBLink.cpp Thu Sep 06 19:22:32 2012 +0200 @@ -9,15 +9,14 @@ #include <QtSql/QSqlRecord> #include "Exception/SQLException.hpp" - -#include <cassert> +#include "Exception/IOException.hpp" SqliteDBLink::SqliteDBLink(const QString& dbPath) { db = QSqlDatabase::addDatabase("QSQLITE", "SqliteDBLink"); db.setDatabaseName(dbPath); - bool ok = db.open(); - assert(ok); + if (!db.open()) + throw IOException(QString("Unable to open SQLite database with path '%1'").arg(dbPath)); QSqlQuery query(db); if (!query.exec(QString("SELECT * FROM files;"))) { query.exec("CREATE TABLE files(path VARCHAR PRIMARY KEY ASC, size INTEGER, mtime TEXT, checksum TEXT);");
