bzr branch
http://bzr.ed.am/sqlite3cc
1
by edam
- initial commit |
1 |
/* |
2
by edam
- further initial development |
2 |
* exception.h |
1
by edam
- initial commit |
3 |
* |
4 |
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org> |
|
5 |
* |
|
2
by edam
- further initial development |
6 |
* This file is part of sqlite3cc (hereafter referred to as "this program"). |
7 |
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information. |
|
1
by edam
- initial commit |
8 |
* |
9 |
* This program is free software: you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU Lesser General Public License as published |
|
11 |
* by the Free Software Foundation, either version 3 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU Lesser General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU Lesser General Public License |
|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21 |
*/ |
|
22 |
||
2
by edam
- further initial development |
23 |
#ifndef SQLITE3CC_EXCEPTION_H_ |
24 |
#define SQLITE3CC_EXCEPTION_H_ |
|
1
by edam
- initial commit |
25 |
|
26 |
||
27 |
#include <sqlite3.h> |
|
28 |
#include <stdexcept> |
|
29 |
||
30 |
||
31 |
namespace sqlite |
|
32 |
{ |
|
33 |
||
34 |
||
13
by edam
- made basic_statement::step() protected, for use by query and command only |
35 |
class database; |
36 |
||
37 |
||
1
by edam
- initial commit |
38 |
/** |
39 |
* Main (base) sqlite exception class. |
|
40 |
*/ |
|
41 |
class sqlite_error |
|
42 |
: |
|
43 |
public std::exception |
|
44 |
{ |
|
45 |
//______________________________________________________________________________ |
|
46 |
// instantiation |
|
47 |
public: |
|
48 |
||
49 |
/** |
|
13
by edam
- made basic_statement::step() protected, for use by query and command only |
50 |
* Constructor that takes an sqlite error code and a database from which to |
51 |
* determine it's error message |
|
52 |
* @param code the sqlite error code |
|
53 |
* @see sqlite_errmsg() |
|
54 |
*/ |
|
55 |
explicit sqlite_error( |
|
56 |
database &database, |
|
57 |
int code ); |
|
58 |
||
59 |
||
60 |
/** |
|
1
by edam
- initial commit |
61 |
* Constructor that takes an sqlite error code and determines it's own |
13
by edam
- made basic_statement::step() protected, for use by query and command only |
62 |
* generic error message |
9
by edam
- added NEWS |
63 |
* @param code the sqlite error code |
1
by edam
- initial commit |
64 |
*/ |
2
by edam
- further initial development |
65 |
explicit sqlite_error( |
9
by edam
- added NEWS |
66 |
int code ); |
1
by edam
- initial commit |
67 |
|
68 |
/** |
|
69 |
* Constructor that allows the creation of an sqlite error with a custom |
|
70 |
* message. |
|
71 |
* @param message a customer error message string |
|
9
by edam
- added NEWS |
72 |
* @param code the sqlite error code |
1
by edam
- initial commit |
73 |
*/ |
2
by edam
- further initial development |
74 |
explicit sqlite_error( |
1
by edam
- initial commit |
75 |
const std::string &message, |
9
by edam
- added NEWS |
76 |
int code = SQLITE_ERROR ); |
1
by edam
- initial commit |
77 |
|
78 |
virtual ~sqlite_error() throw( ); |
|
79 |
||
80 |
//______________________________________________________________________________ |
|
81 |
// public interface |
|
82 |
public: |
|
83 |
||
84 |
/** |
|
85 |
* Get the sqlite error code associated with this error |
|
86 |
* @returns the sqlite error code |
|
87 |
*/ |
|
9
by edam
- added NEWS |
88 |
int get_code() const; |
1
by edam
- initial commit |
89 |
|
90 |
/** |
|
91 |
* Get the error message |
|
92 |
* @returns the error message |
|
93 |
*/ |
|
94 |
virtual const char* what() const throw( ); |
|
95 |
||
96 |
//______________________________________________________________________________ |
|
97 |
// implementation |
|
98 |
private: |
|
99 |
||
100 |
/** |
|
101 |
* Retrieve an automatic error message for a given sqlite error code |
|
102 |
* @param the sqlite error code |
|
103 |
* @returns the automatic string |
|
104 |
*/ |
|
9
by edam
- added NEWS |
105 |
const std::string &get_message( |
106 |
int code ); |
|
1
by edam
- initial commit |
107 |
|
108 |
/** the error code */ |
|
9
by edam
- added NEWS |
109 |
int _code; |
1
by edam
- initial commit |
110 |
|
111 |
/** the message string */ |
|
112 |
std::string _message; |
|
113 |
||
114 |
}; |
|
115 |
||
116 |
||
2
by edam
- further initial development |
117 |
} // namespace sqlite |
118 |
||
119 |
||
120 |
#endif /* SQLITE3CC_EXCEPTION_H_ */ |