-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.hpp
50 lines (46 loc) · 1.3 KB
/
error.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* error.hpp
*
* Exception include part of Disc Data Base.
*
* Copyright (c) 2010-2011 Wincent Balin
*
* Based upon ddb.pl, created years before and serving faithfully until today.
*
* Uses SQLite database version 3.
*
* Published under MIT license. See LICENSE file for further information.
*/
#ifndef ERROR_HPP
#define ERROR_HPP
#include <exception>
#include <string>
// Modeled after the RtError class from RtAudio package
class DBError : public std::exception
{
public:
enum Type
{
UNSPECIFIED,
WARNING,
FILE_ERROR,
RESOURCE_BUSY,
PREPARE_STATEMENT,
BIND_PARAMETER,
EXECUTE_STATEMENT,
RESET_STATEMENT,
FINALIZE_STATEMENT,
BEGIN_TRANSACTION,
END_TRANSACTION
};
DBError(const std::string& message, Type type = DBError::WARNING) throw() : msg(message), t(type) {}
virtual ~DBError(void) throw() {}
virtual void print_message(void) const throw() { std::cerr << std::endl << msg << std::endl << std::endl; }
virtual const Type& get_type(void) const throw() { return t; }
virtual const std::string& get_message(void) const throw() { return msg; }
virtual const char* what(void) const throw() { return msg.c_str(); }
protected:
std::string msg;
Type t;
};
#endif /* ERROR_HPP */