Improved connection error handling.

Just returning a boolean is too limiting. Using expection instead to easily pass on error message.
This commit is contained in:
eelke 2018-12-23 08:43:43 +01:00
parent 646b18ebeb
commit a88af1ac11
5 changed files with 41 additions and 41 deletions

View file

@ -54,15 +54,21 @@ bool Connection::connect(const char *params)
return result;
}
bool Connection::connect(const char *const * keywords, const char* const * values, int expand_dbname)
void Connection::connect(const char *const * keywords, const char* const * values, int expand_dbname)
{
bool result = false;
conn = PQconnectdbParams(keywords, values, expand_dbname);
std::string error_msg;
if (conn) {
ConnStatusType status = PQstatus(conn);
result = (status == CONNECTION_OK);
if (status == CONNECTION_OK)
return;
error_msg = PQerrorMessage(conn);
}
return result;
else {
error_msg = "Unknown connection failure (maybe out of memory?)";
}
throw PgException(error_msg);
}
bool Connection::connectStart(const char* params)