modified app/include/database.hpp +2 -3
| @@ -23,7 +23,6 @@ private: |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public: |
| 26 | | - bool successfullyCreated{ true }; |
| 27 | 26 | |
| 28 | 27 | Database(std::filesystem::path databasePath) { |
| 29 | 28 | loadDatabase(databasePath); |
| @@ -41,7 +40,7 @@ public: |
| 41 | 40 | if (exit != SQLITE_OK) { |
| 42 | 41 | //printMessage("Error with command: " + command + " " + messageError); |
| 43 | 42 | sqlite3_free(messageError); |
| 44 | | - successfullyCreated = false; |
| 43 | + throw std::exception(); |
| 45 | 44 | } |
| 46 | 45 | } |
| 47 | 46 | |
| @@ -56,7 +55,7 @@ public: |
| 56 | 55 | if (exit) { |
| 57 | 56 | std::cerr << "Error opening database" << sqlite3_errmsg(database) |
| 58 | 57 | << std::endl; |
| 59 | | - successfullyCreated = false; |
| 58 | + throw std::exception(); |
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | //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 { |
| 155 | 155 | |
| 156 | 156 | auto main(int argc, char const *argv[]) -> int { |
| 157 | 157 | 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(); |
| 163 | 161 | |
| 164 | | - if (argc > 1) { |
| 165 | | - handleCommand(argc, argv, database); |
| 162 | + if (argc > 1) { |
| 163 | + handleCommand(argc, argv, database); |
| 164 | + } |
| 165 | + else { |
| 166 | + runConsoleApp(); |
| 167 | + } |
| 166 | 168 | } |
| 167 | | - else { |
| 168 | | - runConsoleApp(); |
| 169 | + catch(...) { |
| 170 | + return EXIT_FAILURE; |
| 169 | 171 | } |
| 170 | 172 | |
| 171 | 173 | 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; |