chore: Do exception handling to prevent appliation crash
This commit is contained in:
@@ -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()
|
||||
@@ -108,6 +116,8 @@ void FoodDeliveryController::login()
|
||||
}
|
||||
|
||||
void FoodDeliveryController::registerUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string username, password, phone, name, email;
|
||||
util::clear();
|
||||
@@ -158,6 +168,11 @@ void FoodDeliveryController::registerUser()
|
||||
}
|
||||
std::cout << "User Registration Successful\n";
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void FoodDeliveryController::listRestaurants()
|
||||
{
|
||||
@@ -206,6 +221,8 @@ void FoodDeliveryController::addNewRestaurant()
|
||||
}
|
||||
|
||||
void FoodDeliveryController::updateRestaurantStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
util::clear();
|
||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||
@@ -258,6 +275,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)
|
||||
|
||||
Reference in New Issue
Block a user