juk3n/fluffypublic Fork
⑂ b2c4551
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

added throwing exception when database creation failure

juk3n committed 2024-07-03T18:33:34+02:00 Browse files
b2c4551 parent: 770783e
modified app/include/database.hpp +2 -3
@@ -23,7 +23,6 @@ private:
2323 }
2424
2525 public:
26- bool successfullyCreated{ true };
2726
2827 Database(std::filesystem::path databasePath) {
2928 loadDatabase(databasePath);
@@ -41,7 +40,7 @@ public:
4140 if (exit != SQLITE_OK) {
4241 //printMessage("Error with command: " + command + " " + messageError);
4342 sqlite3_free(messageError);
44- successfullyCreated = false;
43+ throw std::exception();
4544 }
4645 }
4746
@@ -56,7 +55,7 @@ public:
5655 if (exit) {
5756 std::cerr << "Error opening database" << sqlite3_errmsg(database)
5857 << std::endl;
59- successfullyCreated = false;
58+ throw std::exception();
6059 }
6160
6261 //printMessage("Opened database successfully!");
@@ -23,7 +23,6 @@ private:
23 }23 }
24 24
25 public:25 public:
26- bool successfullyCreated{ true };
27 26
28 Database(std::filesystem::path databasePath) {27 Database(std::filesystem::path databasePath) {
29 loadDatabase(databasePath);28 loadDatabase(databasePath);
@@ -41,7 +40,7 @@ public:
41 if (exit != SQLITE_OK) {40 if (exit != SQLITE_OK) {
42 //printMessage("Error with command: " + command + " " + messageError);41 //printMessage("Error with command: " + command + " " + messageError);
43 sqlite3_free(messageError);42 sqlite3_free(messageError);
44- successfullyCreated = false;43+ throw std::exception();
45 }44 }
46 }45 }
47 46
@@ -56,7 +55,7 @@ public:
56 if (exit) {55 if (exit) {
57 std::cerr << "Error opening database" << sqlite3_errmsg(database)56 std::cerr << "Error opening database" << sqlite3_errmsg(database)
58 << std::endl;57 << std::endl;
59- successfullyCreated = false;58+ throw std::exception();
60 }59 }
61 60
62 //printMessage("Opened database successfully!");61 //printMessage("Opened database successfully!");
modified app/src/main.cpp +11 -9
@@ -155,17 +155,19 @@ auto getExecutablePath() -> std::filesystem::path {
155155
156156 auto main(int argc, char const *argv[]) -> int {
157157 auto databasePath{ std::filesystem::path(getExecutablePath().parent_path().string() + "/data.db")};
158- Database database{databasePath};
159-
160- if (!database.successfullyCreated) return EXIT_FAILURE;
161-
162- games = database.getGames();
158+ try {
159+ Database database{databasePath};
160+ games = database.getGames();
163161
164- if (argc > 1) {
165- handleCommand(argc, argv, database);
162+ if (argc > 1) {
163+ handleCommand(argc, argv, database);
164+ }
165+ else {
166+ runConsoleApp();
167+ }
166168 }
167- else {
168- runConsoleApp();
169+ catch(...) {
170+ return EXIT_FAILURE;
169171 }
170172
171173 return EXIT_SUCCESS;
@@ -155,17 +155,19 @@ auto getExecutablePath() -> std::filesystem::path {
155 155
156 auto main(int argc, char const *argv[]) -> int {156 auto main(int argc, char const *argv[]) -> int {
157 auto databasePath{ std::filesystem::path(getExecutablePath().parent_path().string() + "/data.db")};157 auto databasePath{ std::filesystem::path(getExecutablePath().parent_path().string() + "/data.db")};
158- Database database{databasePath};158+ try {
159- 159+ Database database{databasePath};
160- if (!database.successfullyCreated) return EXIT_FAILURE;160+ games = database.getGames();
161-
162- games = database.getGames();
163 161
164- if (argc > 1) {162+ if (argc > 1) {
165- handleCommand(argc, argv, database);163+ handleCommand(argc, argv, database);
164+ }
165+ else {
166+ runConsoleApp();
167+ }
166 }168 }
167- else {169+ catch(...) {
168- runConsoleApp();170+ return EXIT_FAILURE;
169 }171 }
170 172
171 return EXIT_SUCCESS;173 return EXIT_SUCCESS;