Misc minor changes.
This commit is contained in:
parent
36e5526f5f
commit
a06c752029
3 changed files with 47 additions and 12 deletions
|
|
@ -1,23 +1,52 @@
|
|||
#ifndef PGEXCEPTION_H
|
||||
#ifndef PGEXCEPTION_H
|
||||
#define PGEXCEPTION_H
|
||||
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace Pgsql {
|
||||
|
||||
class PgException {
|
||||
class ResultCode {
|
||||
public:
|
||||
explicit ResultCode(std::string result_code)
|
||||
: m_resultCode(std::move(result_code))
|
||||
{
|
||||
assert(m_resultCode.length() == 5);
|
||||
}
|
||||
|
||||
std::string getClass() const
|
||||
{
|
||||
return m_resultCode.substr(1,2);
|
||||
}
|
||||
|
||||
/** Helper to easily check the class of the error
|
||||
*
|
||||
*/
|
||||
bool isClass(const std::string_view cls)
|
||||
{
|
||||
return m_resultCode.compare(1, 2, cls);
|
||||
}
|
||||
|
||||
const std::string& getSpecific() const
|
||||
{
|
||||
return m_resultCode;
|
||||
}
|
||||
private:
|
||||
std::string m_resultCode;
|
||||
};
|
||||
|
||||
class PgException: public std::runtime_error {
|
||||
public:
|
||||
PgException(const char *msg)
|
||||
: message(msg)
|
||||
: std::runtime_error(msg)
|
||||
{}
|
||||
PgException(std::string msg)
|
||||
: message(std::move(msg))
|
||||
{}
|
||||
: std::runtime_error(msg)
|
||||
{}
|
||||
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -25,14 +54,21 @@ namespace Pgsql {
|
|||
public:
|
||||
PgResultError(std::string msg, std::string result_code)
|
||||
: PgException(std::move(msg))
|
||||
, m_resultCode(result_code)
|
||||
{}
|
||||
|
||||
ResultCode getResultCode() const { return m_resultCode; }
|
||||
private:
|
||||
ResultCode m_resultCode;
|
||||
};
|
||||
|
||||
class PgConnectionError: public PgResultError, std::runtime_error {
|
||||
class PgConnectionError: public PgResultError {
|
||||
public:
|
||||
PgConnectionError(const std::string &msg, std::string result_code)
|
||||
: PgResultError(msg, std::move(result_code))
|
||||
, std::runtime_error(msg)
|
||||
{}
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue