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

@ -2,19 +2,33 @@
#define OPENDATABASE_H
#include "ConnectionConfig.h"
#include "Expected.h"
#include <QException>
#include <memory>
class PgDatabaseCatalog;
class TypeSelectionItemModel;
class OpenDatabaseException : public QException {
public:
OpenDatabaseException(QString message)
: m_message(std::move(message))
{}
QString text() const { return m_message; }
void raise() const override { throw *this; }
OpenDatabaseException *clone() const override { return new OpenDatabaseException(*this); }
private:
QString m_message;
};
/** Instances of this class represent a single database on which atleast one
* window is opened. This class is used to track details about that database.
*/
class OpenDatabase {
public:
using OpenDatabaseSPtr = std::shared_ptr<OpenDatabase>;
static Expected<OpenDatabaseSPtr> createOpenDatabase(const ConnectionConfig &cfg);
static OpenDatabaseSPtr createOpenDatabase(const ConnectionConfig &cfg);
// using on_createResult_callback = std::function<void(Expected<std::shared_ptr<Pgsql::Result>>)>;
// void asyncCreateOpenDatabase(const ConnectionConfig &cfg, on_createResult_callback);