pgLab/pgsql/Pgsql_PgException.h

131 lines
2.9 KiB
C
Raw Normal View History

2017-12-28 09:20:42 +01:00
#ifndef PGEXCEPTION_H
#define PGEXCEPTION_H
2017-12-28 09:20:42 +01:00
#include <cassert>
#include <stdexcept>
#include <utility>
namespace Pgsql {
2017-12-28 09:20:42 +01:00
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)
2017-12-28 09:20:42 +01:00
: std::runtime_error(msg)
{}
PgException(std::string msg)
2017-12-28 09:20:42 +01:00
: std::runtime_error(msg)
{}
private:
};
class PgResultError: public PgException {
public:
PgResultError(std::string msg, std::string result_code)
: PgException(std::move(msg))
2017-12-28 09:20:42 +01:00
, m_resultCode(result_code)
{}
2017-12-28 09:20:42 +01:00
ResultCode getResultCode() const { return m_resultCode; }
private:
ResultCode m_resultCode;
};
2017-12-28 09:20:42 +01:00
class PgConnectionError: public PgResultError {
public:
PgConnectionError(const std::string &msg, std::string result_code)
: PgResultError(msg, std::move(result_code))
{}
2017-12-28 09:20:42 +01:00
private:
};
/* postgresq error classes
*
* success
* warning
* no data
*
* 03 sql statement not yet complete
* 08 connection exception -> could be resolved by reconnecting / resetting connection
* 09 triggered action exception
* 0A feature not supported
* 0B invalid transaction initiation
* 0F locator exception
* 0L invalid grantor
* 0P invalid role
* 0Z diagnostic exception
* 20 case not fount
* 21 cardinality violation
* 22 data exception
* 23 integrity constraint error
* 24 invalid cursor statement
* 25 invalid transaction state
* 26 invalid sql statement name
* 27 triggered data change violation
* 28 invalid authorization specification
* 2B Dependent Privilege Descriptors Still Exist
* 2D Invalid Transaction Termination
* 2F SQL Routine Exception
* 34 Invalid Cursor Name
* 38 External Routine Exception
* 39 External Routine Invocation Exception
* 3B Savepoint Exception
* 3D Invalid Catalog Name
* 3F Invalid Schema Name
* 40 Transaction Rollback
* 42 Syntax Error or Access Rule Violation
* 44 WITH CHECK OPTION Violation
* 53 Insufficient Resources
* 54 Program Limit Exceeded
* 55 Object Not In Prerequisite State
* 57 Operator Intervention
* 58 System Error (errors external to PostgreSQL itself)
* 72 Snapshot Failure
* F0 Configuration File Error
* HV Foreign Data Wrapper Error (SQL/MED)
* P0 PL/pgSQL Error
* XX Internal Error
*
* At what levels can the communication with postgresql fail
* - network -> reset/reconnecting
* -
*/
}
#endif // PGEXCEPTION_H