[core] throw values, catch references
This commit is contained in:
@@ -19,7 +19,7 @@ const static bool sqliteVersionCheck = []() {
|
||||
|
||||
return true;
|
||||
}();
|
||||
#pragma GCC diagnostic pop
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapbox {
|
||||
namespace sqlite {
|
||||
@@ -27,9 +27,9 @@ namespace sqlite {
|
||||
Database::Database(const std::string &filename, int flags) {
|
||||
const int err = sqlite3_open_v2(filename.c_str(), &db, flags, nullptr);
|
||||
if (err != SQLITE_OK) {
|
||||
Exception ex { err, sqlite3_errmsg(db) };
|
||||
const auto message = sqlite3_errmsg(db);
|
||||
db = nullptr;
|
||||
throw ex;
|
||||
throw Exception { err, message };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,9 @@ void Database::exec(const std::string &sql) {
|
||||
char *msg = nullptr;
|
||||
const int err = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &msg);
|
||||
if (msg) {
|
||||
Exception ex { err, msg };
|
||||
const std::string message = msg;
|
||||
sqlite3_free(msg);
|
||||
throw ex;
|
||||
throw Exception { err, message };
|
||||
} else if (err != SQLITE_OK) {
|
||||
throw Exception { err, sqlite3_errmsg(db) };
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ enum OpenFlag : int {
|
||||
|
||||
struct Exception : std::runtime_error {
|
||||
inline Exception(int err, const char *msg) : std::runtime_error(msg), code(err) {}
|
||||
inline Exception(int err, const std::string& msg) : std::runtime_error(msg), code(err) {}
|
||||
const int code = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ protected:
|
||||
}
|
||||
|
||||
if (i * itemSize >= pos) {
|
||||
throw new std::runtime_error("Can't get element after array bounds");
|
||||
throw std::runtime_error("Can't get element after array bounds");
|
||||
} else {
|
||||
return reinterpret_cast<char *>(array) + (i * itemSize);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ void ThreadContext::setFileSource(FileSource* fileSource) {
|
||||
if (current.get() != nullptr) {
|
||||
current.get()->fileSource = fileSource;
|
||||
} else {
|
||||
throw new std::runtime_error("Current thread has no current ThreadContext.");
|
||||
throw std::runtime_error("Current thread has no current ThreadContext.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void ThreadContext::setGLObjectStore(GLObjectStore* glObjectStore) {
|
||||
if (current.get() != nullptr) {
|
||||
current.get()->glObjectStore = glObjectStore;
|
||||
} else {
|
||||
throw new std::runtime_error("Current thread has no current ThreadContext.");
|
||||
throw std::runtime_error("Current thread has no current ThreadContext.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ public:
|
||||
});
|
||||
|
||||
if (ret) {
|
||||
throw new std::runtime_error("Failed to init local storage key.");
|
||||
throw std::runtime_error("Failed to init local storage key.");
|
||||
}
|
||||
}
|
||||
|
||||
inline ~ThreadLocal() {
|
||||
if (pthread_key_delete(key)) {
|
||||
throw new std::runtime_error("Failed to delete local storage key.");
|
||||
throw std::runtime_error("Failed to delete local storage key.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
inline void set(T* ptr) {
|
||||
if (pthread_setspecific(key, ptr)) {
|
||||
throw new std::runtime_error("Failed to set local storage.");
|
||||
throw std::runtime_error("Failed to set local storage.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user