-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy patherror.cpp
69 lines (54 loc) · 1.55 KB
/
error.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// (c) 2014 Stephan Hohe
#include "error.hpp"
#include <sqlite3.h>
#include <iostream>
namespace sqxx {
#if (SQLITE_VERSION_NUMBER >= 3007015)
static_error::static_error(int code_arg) : error(code_arg, sqlite3_errstr(code_arg)) {
}
#else
static_error::static_error(int code_arg) : error(code_arg, "sqlite error " + std::to_string(code_arg)) {
}
#endif
managed_error::managed_error(int code_arg, char *what_arg) : error(code_arg, what_arg), sqlitestr(what_arg) {
}
managed_error::~managed_error() noexcept {
sqlite3_free(sqlitestr);
}
static callback_exception_handler_t callback_exception_handler = default_callback_exception_handler;
void set_callback_exception_handler(const callback_exception_handler_t &fun) {
callback_exception_handler = fun;
}
void default_callback_exception_handler(const char *cbname, std::exception_ptr ex) noexcept {
std::cerr << "SQXX: uncaught exeption in " << cbname << ": ";
if (!ex) {
std::cerr << "(exception not captured)";
}
else {
try {
std::rethrow_exception(ex);
}
catch (const std::exception &rex) {
const char *what = rex.what();
if (what)
std::cerr << what;
else
std::cerr << "(no message)";
}
catch (...) {
std::cerr << "(unknown exception type)";
}
}
std::cerr << std::endl;
}
void handle_callback_exception(const char *cbname) {
if (callback_exception_handler) {
try {
callback_exception_handler(cbname, std::current_exception());
}
catch (...) {
default_callback_exception_handler("callback exception handler", std::current_exception());
}
}
}
} // namespace sqxx