Skip to content

Commit 6dff9bf

Browse files
committed
fix: exception handling
1 parent 5699a5d commit 6dff9bf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

example/src/tests/unitTests.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ export function registerUnitTests() {
560560
await promised
561561
expect.fail('Should not resolve')
562562
} catch (e) {
563-
console.log(e)
564-
565563
if (isError(e))
566564
expect(e.message).to.include('no such table: tableThatDoesNotExist')
567565
else expect.fail('Should have thrown a valid NitroSQLiteException')

package/cpp/NitroSQLiteException.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,22 @@ inline std::string typeToString(NitroSQLiteExceptionType type) {
2828
return exceptionTypeStrings[type];
2929
}
3030

31-
class NitroSQLiteException : public std::runtime_error {
31+
class NitroSQLiteException : public std::exception {
3232
public:
3333
explicit NitroSQLiteException(const char* message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
3434
explicit NitroSQLiteException(const std::string& message): NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
3535
NitroSQLiteException(const NitroSQLiteExceptionType& type, const char* message) : NitroSQLiteException(type, std::string(message)) {}
3636
NitroSQLiteException(const NitroSQLiteExceptionType& type, const std::string& message)
37-
: std::runtime_error("[react-native-nitro-sqlite] " + typeToString(type) + ": " + message) {}
37+
: _exceptionString("[" + typeToString(type) + "] " + message) {}
38+
39+
private:
40+
const std::string _exceptionString;
3841

3942
public:
43+
[[nodiscard]] const char* what() const noexcept override {
44+
return this->_exceptionString.c_str();
45+
}
46+
4047
static NitroSQLiteException DatabaseNotOpen(const std::string& dbName) {
4148
return NitroSQLiteException(NitroSQLiteExceptionType::UnableToAttachToDatabase, dbName + " is not open");
4249
}

0 commit comments

Comments
 (0)