CodeCommitsIssuesPull requestsActionsInsightsSecurity
70034b6232840c23f0ccb4e5d3ad5fb78bd625e7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

base/mysqlxx/Exception.h

53lines · modecode

1#pragma once
2
3#include <sstream>
4#include <Poco/Exception.h>
5#include <mysqlxx/Types.h>
6
7
8namespace mysqlxx
9{
10/// Common exception class for MySQL library. Functions code() and errnum() return error numbers from MySQL, for details see mysqld_error.h
11struct Exception : public Poco::Exception
12{
13 Exception(const std::string & msg, int code = 0) : Poco::Exception(msg, code) {}
14 int errnum() const { return code(); }
15 const char * name() const throw() override { return "mysqlxx::Exception"; }
16 const char * className() const throw() override { return "mysqlxx::Exception"; }
17};
18
19
20/// Cannot connect to MySQL server
21struct ConnectionFailed : public Exception
22{
23 ConnectionFailed(const std::string & msg, int code = 0) : Exception(msg, code) {}
24 const char * name() const throw() override { return "mysqlxx::ConnectionFailed"; }
25 const char * className() const throw() override { return "mysqlxx::ConnectionFailed"; }
26};
27
28
29/// Erroneous query.
30struct BadQuery : public Exception
31{
32 BadQuery(const std::string & msg, int code = 0) : Exception(msg, code) {}
33 const char * name() const throw() override { return "mysqlxx::BadQuery"; }
34 const char * className() const throw() override { return "mysqlxx::BadQuery"; }
35};
36
37
38/// Value parsing failure
39struct CannotParseValue : public Exception
40{
41 CannotParseValue(const std::string & msg, int code = 0) : Exception(msg, code) {}
42 const char * name() const throw() override { return "mysqlxx::CannotParseValue"; }
43 const char * className() const throw() override { return "mysqlxx::CannotParseValue"; }
44};
45
46
47std::string errorMessage(MYSQL * driver);
48
49/// For internal need of library.
50void checkError(MYSQL * driver);
51[[noreturn]] void onError(MYSQL * driver);
52
53}