Skip to content

Commit 1b956b7

Browse files
committed
Move list of error codes into reusable file
1 parent ef55b8e commit 1b956b7

File tree

2 files changed

+37
-53
lines changed

2 files changed

+37
-53
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,10 @@ namespace sqlite {
5656
//SQLITE_OK, SQLITE_NOTICE, SQLITE_WARNING, SQLITE_ROW, SQLITE_DONE
5757
//
5858
//Note these names are exact matches to the names of the SQLITE error codes.
59-
class error: public sqlite_exception { using sqlite_exception::sqlite_exception; };
60-
class internal: public sqlite_exception{ using sqlite_exception::sqlite_exception; };
61-
class perm: public sqlite_exception { using sqlite_exception::sqlite_exception; };
62-
class abort: public sqlite_exception { using sqlite_exception::sqlite_exception; };
63-
class busy: public sqlite_exception { using sqlite_exception::sqlite_exception; };
64-
class locked: public sqlite_exception { using sqlite_exception::sqlite_exception; };
65-
class nomem: public sqlite_exception { using sqlite_exception::sqlite_exception; };
66-
class readonly: public sqlite_exception { using sqlite_exception::sqlite_exception; };
67-
class interrupt: public sqlite_exception { using sqlite_exception::sqlite_exception; };
68-
class ioerr: public sqlite_exception { using sqlite_exception::sqlite_exception; };
69-
class corrupt: public sqlite_exception { using sqlite_exception::sqlite_exception; };
70-
class notfound: public sqlite_exception { using sqlite_exception::sqlite_exception; };
71-
class full: public sqlite_exception { using sqlite_exception::sqlite_exception; };
72-
class cantopen: public sqlite_exception { using sqlite_exception::sqlite_exception; };
73-
class protocol: public sqlite_exception { using sqlite_exception::sqlite_exception; };
74-
class empty: public sqlite_exception { using sqlite_exception::sqlite_exception; };
75-
class schema: public sqlite_exception { using sqlite_exception::sqlite_exception; };
76-
class toobig: public sqlite_exception { using sqlite_exception::sqlite_exception; };
77-
class constraint: public sqlite_exception { using sqlite_exception::sqlite_exception; };
78-
class mismatch: public sqlite_exception { using sqlite_exception::sqlite_exception; };
79-
class misuse: public sqlite_exception { using sqlite_exception::sqlite_exception; };
80-
class nolfs: public sqlite_exception { using sqlite_exception::sqlite_exception; };
81-
class auth: public sqlite_exception { using sqlite_exception::sqlite_exception; };
82-
class format: public sqlite_exception { using sqlite_exception::sqlite_exception; };
83-
class range: public sqlite_exception { using sqlite_exception::sqlite_exception; };
84-
class notadb: public sqlite_exception { using sqlite_exception::sqlite_exception; };
59+
#define SQLITE_MODERN_CPP_ERROR_CODE(NAME,name,derived) \
60+
class name: public sqlite_exception { using sqlite_exception::sqlite_exception; };
61+
#include "sqlite_modern_cpp/lists/error_codes.h"
62+
#undef SQLITE_MODERN_CPP_ERROR_CODE
8563

8664
//Some additional errors are here for the C++ interface
8765
class more_rows: public sqlite_exception { using sqlite_exception::sqlite_exception; };
@@ -90,33 +68,13 @@ namespace sqlite {
9068
class more_statements: public sqlite_exception { using sqlite_exception::sqlite_exception; }; // Prepared statements can only contain one statement
9169

9270
static void throw_sqlite_error(const int& error_code, const std::string &sql = "") {
93-
if(error_code == SQLITE_ERROR) throw exceptions::error(error_code, sql);
94-
else if(error_code == SQLITE_INTERNAL) throw exceptions::internal(error_code, sql);
95-
else if(error_code == SQLITE_PERM) throw exceptions::perm(error_code, sql);
96-
else if(error_code == SQLITE_ABORT) throw exceptions::abort(error_code, sql);
97-
else if(error_code == SQLITE_BUSY) throw exceptions::busy(error_code, sql);
98-
else if(error_code == SQLITE_LOCKED) throw exceptions::locked(error_code, sql);
99-
else if(error_code == SQLITE_NOMEM) throw exceptions::nomem(error_code, sql);
100-
else if(error_code == SQLITE_READONLY) throw exceptions::readonly(error_code, sql);
101-
else if(error_code == SQLITE_INTERRUPT) throw exceptions::interrupt(error_code, sql);
102-
else if(error_code == SQLITE_IOERR) throw exceptions::ioerr(error_code, sql);
103-
else if(error_code == SQLITE_CORRUPT) throw exceptions::corrupt(error_code, sql);
104-
else if(error_code == SQLITE_NOTFOUND) throw exceptions::notfound(error_code, sql);
105-
else if(error_code == SQLITE_FULL) throw exceptions::full(error_code, sql);
106-
else if(error_code == SQLITE_CANTOPEN) throw exceptions::cantopen(error_code, sql);
107-
else if(error_code == SQLITE_PROTOCOL) throw exceptions::protocol(error_code, sql);
108-
else if(error_code == SQLITE_EMPTY) throw exceptions::empty(error_code, sql);
109-
else if(error_code == SQLITE_SCHEMA) throw exceptions::schema(error_code, sql);
110-
else if(error_code == SQLITE_TOOBIG) throw exceptions::toobig(error_code, sql);
111-
else if(error_code == SQLITE_CONSTRAINT) throw exceptions::constraint(error_code, sql);
112-
else if(error_code == SQLITE_MISMATCH) throw exceptions::mismatch(error_code, sql);
113-
else if(error_code == SQLITE_MISUSE) throw exceptions::misuse(error_code, sql);
114-
else if(error_code == SQLITE_NOLFS) throw exceptions::nolfs(error_code, sql);
115-
else if(error_code == SQLITE_AUTH) throw exceptions::auth(error_code, sql);
116-
else if(error_code == SQLITE_FORMAT) throw exceptions::format(error_code, sql);
117-
else if(error_code == SQLITE_RANGE) throw exceptions::range(error_code, sql);
118-
else if(error_code == SQLITE_NOTADB) throw exceptions::notadb(error_code, sql);
119-
else throw sqlite_exception(error_code, sql);
71+
switch(error_code) {
72+
#define SQLITE_MODERN_CPP_ERROR_CODE(NAME,name,derived) \
73+
case SQLITE_ ## NAME: throw exceptions::name(error_code, sql);
74+
#include "sqlite_modern_cpp/lists/error_codes.h"
75+
#undef SQLITE_MODERN_CPP_ERROR_CODE
76+
default: throw sqlite_exception(error_code, sql);
77+
}
12078
}
12179
}
12280
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SQLITE_MODERN_CPP_ERROR_CODE(ERROR,error,)
2+
SQLITE_MODERN_CPP_ERROR_CODE(INTERNAL,internal,)
3+
SQLITE_MODERN_CPP_ERROR_CODE(PERM,perm,)
4+
SQLITE_MODERN_CPP_ERROR_CODE(ABORT,abort,)
5+
SQLITE_MODERN_CPP_ERROR_CODE(BUSY,busy,)
6+
SQLITE_MODERN_CPP_ERROR_CODE(LOCKED,locked,)
7+
SQLITE_MODERN_CPP_ERROR_CODE(NOMEM,nomem,)
8+
SQLITE_MODERN_CPP_ERROR_CODE(READONLY,readonly,)
9+
SQLITE_MODERN_CPP_ERROR_CODE(INTERRUPT,interrupt,)
10+
SQLITE_MODERN_CPP_ERROR_CODE(IOERR,ioerr,)
11+
SQLITE_MODERN_CPP_ERROR_CODE(CORRUPT,corrupt,)
12+
SQLITE_MODERN_CPP_ERROR_CODE(NOTFOUND,notfound,)
13+
SQLITE_MODERN_CPP_ERROR_CODE(FULL,full,)
14+
SQLITE_MODERN_CPP_ERROR_CODE(CANTOPEN,cantopen,)
15+
SQLITE_MODERN_CPP_ERROR_CODE(PROTOCOL,protocol,)
16+
SQLITE_MODERN_CPP_ERROR_CODE(EMPTY,empty,)
17+
SQLITE_MODERN_CPP_ERROR_CODE(SCHEMA,schema,)
18+
SQLITE_MODERN_CPP_ERROR_CODE(TOOBIG,toobig,)
19+
SQLITE_MODERN_CPP_ERROR_CODE(CONSTRAINT,constraint,)
20+
SQLITE_MODERN_CPP_ERROR_CODE(MISMATCH,mismatch,)
21+
SQLITE_MODERN_CPP_ERROR_CODE(MISUSE,misuse,)
22+
SQLITE_MODERN_CPP_ERROR_CODE(NOLFS,nolfs,)
23+
SQLITE_MODERN_CPP_ERROR_CODE(AUTH,auth,)
24+
SQLITE_MODERN_CPP_ERROR_CODE(FORMAT,format,)
25+
SQLITE_MODERN_CPP_ERROR_CODE(RANGE,range,)
26+
SQLITE_MODERN_CPP_ERROR_CODE(NOTADB,notadb,)

0 commit comments

Comments
 (0)