Sqlitepp  1.2.3
A thin sqlite C++ wrapper
error.hpp
Go to the documentation of this file.
1 
4 // Copyright 2019 Matthew Chandler
5 
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 
24 #ifndef SQLITE_ERROR_HPP
25 #define SQLITE_ERROR_HPP
26 
27 #include <stdexcept>
28 #include <string>
29 
30 #include <sqlitepp/sqlite3.h>
31 
33 namespace sqlite
34 {
36  // ideally, this would be a concrete class deriving from std::exception,
37  // but then our derived exceptions below couldn't derive from std::runtime & logic_errors
38  class Error
39  {
40  public:
41  virtual ~Error() = 0;
42 
44  virtual const char * sql() const noexcept;
45 
47  virtual int err_code() const noexcept;
48 
50  virtual const char * err_str() const noexcept;
51 
53  virtual const char * err_msg() const noexcept;
54 
55  protected:
59  Error(const std::string & sql, int sqlite_error_code, sqlite3 * db);
60 
61  private:
62  std::string sql_;
63  int sqlite_error_code_;
64  sqlite3 * db_;
65  };
66 
68  class Logic_error: public virtual std::logic_error, public Error
69  {
70  public:
75  Logic_error(const std::string & what, const std::string & sql,
76  int sqlite_error_code, sqlite3 * db);
77  virtual ~Logic_error() = default;
78  };
79 
81  class Runtime_error: public virtual std::runtime_error, public Error
82  {
83  public:
88  Runtime_error(const std::string & what, const std::string & sql,
89  int sqlite_error_code, sqlite3 * db);
90  virtual ~Runtime_error() = default;
91  };
92 };
93 
94 # endif // SQLITE_ERROR_HPP
virtual const char * err_msg() const noexcept
Get the sqlite3 error message.
Definition: error.cpp:46
Sqlite C++ wrapper and associated types.
Definition: database.hpp:30
SQL Logic error.
Definition: error.hpp:68
SQL Runtime error.
Definition: error.hpp:81
virtual int err_code() const noexcept
Get sqlite3 error code.
Definition: error.cpp:36
virtual const char * sql() const noexcept
Get SQL code where error was thrown.
Definition: error.cpp:31
Error(const std::string &sql, int sqlite_error_code, sqlite3 *db)
Definition: error.cpp:54
virtual const char * err_str() const noexcept
Get a description of the sqlite3 error code.
Definition: error.cpp:41
Common data for SQL errors (abstract base)
Definition: error.hpp:38