/sqlite3cc

To get this branch, use:
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
35
/**
36
 * Main (base) sqlite exception class.
37
 */
38
class sqlite_error
39
	:
40
	public std::exception
41
{
42
//______________________________________________________________________________
43
//                                                                 instantiation
44
public:
45
46
	/**
47
	 * Constructor that takes an sqlite error code and determines it's own
48
	 * error message
49
	 * @param error_code the sqlite error code
50
	 */
2 by edam
- further initial development
51
	explicit sqlite_error(
1 by edam
- initial commit
52
		int error_code );
53
54
	/**
55
	 * Constructor that allows the creation of an sqlite error with a custom
56
	 * message.
57
	 * @param message a customer error message string
58
	 * @param error_code the sqlite error code
59
	 */
2 by edam
- further initial development
60
	explicit sqlite_error(
1 by edam
- initial commit
61
		const std::string &message,
62
		int error_code = SQLITE_ERROR );
63
64
	virtual ~sqlite_error() throw( );
65
66
//______________________________________________________________________________
67
//                                                              public interface
68
public:
69
70
	/**
71
	 * Get the sqlite error code associated with this error
72
	 * @returns the sqlite error code
73
	 */
74
	int get_error_code() const;
75
76
	/**
77
	 * Get the error message
78
	 * @returns the error message
79
	 */
80
	virtual const char* what() const throw( );
81
82
//______________________________________________________________________________
83
//                                                                implementation
84
private:
85
86
	/**
87
	 * Retrieve an automatic error message for a given sqlite error code
88
	 * @param the sqlite error code
89
	 * @returns the automatic string
90
	 */
91
	const std::string &get_error_message(
92
		int error_code );
93
94
	/** the error code */
95
	int _error_code;
96
97
	/** the message string */
98
	std::string _message;
99
100
};
101
102
2 by edam
- further initial development
103
/**
104
 * An sqlite error that indicates the database was busy
105
 */
106
class sqlite_busy
107
	:
108
	public sqlite_error
109
{
110
public:
111
	sqlite_busy()
112
		:
113
		sqlite_error( "database was busy", SQLITE_BUSY )
114
	{ }
115
};
116
117
118
} // namespace sqlite
119
120
121
#endif /* SQLITE3CC_EXCEPTION_H_ */