Fix: openening not accessible database crashes program.

OpenDatabase::createOpenDatabase now uses QException derived exception to report failure.
This makes it possible to catch the exception in a background thread and rethrow it when the Future is read.
Which makes it possible for the database window to properly report the problem.
This commit is contained in:
eelke 2019-01-29 19:41:27 +01:00
parent 3820fb2600
commit ecae0464f9
5 changed files with 36 additions and 24 deletions

View file

@ -1,22 +1,19 @@
#include "OpenDatabase.h"
#include "catalog/PgDatabaseCatalog.h"
#include "Pgsql_Connection.h"
#include "Pgsql_PgException.h"
#include "model/TypeSelectionItemModel.h"
Expected<OpenDatabase::OpenDatabaseSPtr> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
OpenDatabase::OpenDatabaseSPtr OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
{
return Expected<OpenDatabase::OpenDatabaseSPtr>::fromCode(
[&cfg] () -> auto {
OpenDatabaseSPtr odb(new OpenDatabase(cfg));
odb->Init();
return odb;
});
// catch (const PgException &ex) {
// return
// }
// return Expected<OpenDatabaseSPtr>::fromException(
// std::runtime_error("Failed to get database information"));
try {
OpenDatabaseSPtr odb(new OpenDatabase(cfg));
odb->Init();
return odb;
}
catch (const Pgsql::PgException &ex) {
throw OpenDatabaseException(ex.what());
}
}
OpenDatabase::OpenDatabase(const ConnectionConfig& cfg)