From 71e13ea66f52c5b37ebf908d581d8bec1225e585 Mon Sep 17 00:00:00 2001 From: ShenMian Date: Fri, 19 Apr 2024 22:20:41 +0800 Subject: [PATCH] refactor: simplify exception handling and code flow --- src/main.cpp | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 431aa0d..ba32d58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,32 +3,19 @@ #include "gomoku.hpp" -int main() -{ - try - { - Gomoku gomoku; - gomoku.run(); - } - catch(const std::runtime_error& e) - { - std::cerr << "Exception: " << e.what() << "\n"; - std::cerr << "Press enter to exit...\n"; - std::string line; - std::getline(std::cin, line); - std::getline(std::cin, line); - return 1; - } - catch(...) - { - std::cerr << "Unknown exception\b"; - std::cerr << "Press enter to exit...\n"; - std::string line; - std::getline(std::cin, line); - std::getline(std::cin, line); - return 1; - } - - - return 0; +int main() { + try { + Gomoku gomoku; + gomoku.run(); + return 0; + } catch (const std::runtime_error& e) { + std::cerr << "Exception: " << e.what() << "\n"; + } catch (...) { + std::cerr << "Unknown exception\n"; + } + std::cerr << "Press enter to exit...\n"; + std::string line; + std::getline(std::cin, line); + std::getline(std::cin, line); + return 1; }