chore: Do exception handling to prevent appliation crash

This commit is contained in:
Joel Thomas
2026-02-19 20:01:18 +05:30
parent ec31206437
commit 6adc50fbd5
4 changed files with 196 additions and 149 deletions
@@ -13,6 +13,8 @@ void CustomerMenu::showMenu()
{
bool isMenuActive = true;
while (isMenuActive)
{
try
{
int choice;
util::clear();
@@ -30,6 +32,12 @@ void CustomerMenu::showMenu()
isMenuActive = false;
}
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
}
bool CustomerMenu::handleOperation(int choice)
@@ -13,6 +13,8 @@ void DeliveryPartnerMenu::showMenu()
{
bool isMenuActive = true;
while (isMenuActive)
{
try
{
int choice;
util::clear();
@@ -30,6 +32,13 @@ void DeliveryPartnerMenu::showMenu()
isMenuActive = false;
}
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
}
bool DeliveryPartnerMenu::handleOperation(int choice)
@@ -33,23 +33,25 @@ void FoodDeliveryController::run()
bool isMenuActive = true;
while (isMenuActive)
{
char choice;
int choice;
util::clear();
std::cout << "Food Delivery App\n"
"1. Login\n"
"2. Register\n"
"3. Exit\n"
"Choice?: ";
util::readValue<char>(choice);
if (choice == '1')
try
{
util::readValue<int>(choice);
if (choice == 1)
{
login();
}
else if (choice == '2')
else if (choice == 2)
{
registerUser();
}
else if (choice == '3')
else if (choice == 3)
{
break;
}
@@ -59,6 +61,12 @@ void FoodDeliveryController::run()
}
util::pressEnter();
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
}
void FoodDeliveryController::login()
@@ -109,6 +117,8 @@ void FoodDeliveryController::login()
void FoodDeliveryController::registerUser()
{
try
{
std::string username, password, phone, name, email;
util::clear();
std::cout << "Enter Username: ";
@@ -157,6 +167,11 @@ void FoodDeliveryController::registerUser()
break;
}
std::cout << "User Registration Successful\n";
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
}
}
void FoodDeliveryController::listRestaurants()
@@ -207,6 +222,8 @@ void FoodDeliveryController::addNewRestaurant()
void FoodDeliveryController::updateRestaurantStatus()
{
try
{
util::clear();
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
{
@@ -257,6 +274,11 @@ void FoodDeliveryController::updateRestaurantStatus()
}
listRestaurants();
std::cout << "Updated Restaurant " << restaurantIterator->second->getName() << " successfully\n";
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
}
}
void FoodDeliveryController::listRestaurantOrders()
@@ -13,6 +13,8 @@ void RestaurantOwnerMenu::showMenu()
{
bool isMenuActive = true;
while (isMenuActive)
{
try
{
int choice;
util::clear();
@@ -35,6 +37,12 @@ void RestaurantOwnerMenu::showMenu()
isMenuActive = false;
}
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
}
bool RestaurantOwnerMenu::handleOperation(int choice)