chore: Do exception handling to prevent appliation crash
This commit is contained in:
@@ -13,6 +13,8 @@ void CustomerMenu::showMenu()
|
|||||||
{
|
{
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
while (isMenuActive)
|
while (isMenuActive)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
int choice;
|
int choice;
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -30,6 +32,12 @@ void CustomerMenu::showMenu()
|
|||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomerMenu::handleOperation(int choice)
|
bool CustomerMenu::handleOperation(int choice)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ void DeliveryPartnerMenu::showMenu()
|
|||||||
{
|
{
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
while (isMenuActive)
|
while (isMenuActive)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
int choice;
|
int choice;
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -30,6 +32,13 @@ void DeliveryPartnerMenu::showMenu()
|
|||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeliveryPartnerMenu::handleOperation(int choice)
|
bool DeliveryPartnerMenu::handleOperation(int choice)
|
||||||
|
|||||||
@@ -33,23 +33,25 @@ void FoodDeliveryController::run()
|
|||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
while (isMenuActive)
|
while (isMenuActive)
|
||||||
{
|
{
|
||||||
char choice;
|
int choice;
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Food Delivery App\n"
|
std::cout << "Food Delivery App\n"
|
||||||
"1. Login\n"
|
"1. Login\n"
|
||||||
"2. Register\n"
|
"2. Register\n"
|
||||||
"3. Exit\n"
|
"3. Exit\n"
|
||||||
"Choice?: ";
|
"Choice?: ";
|
||||||
util::readValue<char>(choice);
|
try
|
||||||
if (choice == '1')
|
{
|
||||||
|
util::readValue<int>(choice);
|
||||||
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
login();
|
login();
|
||||||
}
|
}
|
||||||
else if (choice == '2')
|
else if (choice == 2)
|
||||||
{
|
{
|
||||||
registerUser();
|
registerUser();
|
||||||
}
|
}
|
||||||
else if (choice == '3')
|
else if (choice == 3)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -59,6 +61,12 @@ void FoodDeliveryController::run()
|
|||||||
}
|
}
|
||||||
util::pressEnter();
|
util::pressEnter();
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::login()
|
void FoodDeliveryController::login()
|
||||||
@@ -108,6 +116,8 @@ void FoodDeliveryController::login()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::registerUser()
|
void FoodDeliveryController::registerUser()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
std::string username, password, phone, name, email;
|
std::string username, password, phone, name, email;
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -158,6 +168,11 @@ void FoodDeliveryController::registerUser()
|
|||||||
}
|
}
|
||||||
std::cout << "User Registration Successful\n";
|
std::cout << "User Registration Successful\n";
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::listRestaurants()
|
void FoodDeliveryController::listRestaurants()
|
||||||
{
|
{
|
||||||
@@ -206,6 +221,8 @@ void FoodDeliveryController::addNewRestaurant()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::updateRestaurantStatus()
|
void FoodDeliveryController::updateRestaurantStatus()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
if (!checkAccess(m_authenticatedUser, "RestaurantOwner"))
|
||||||
@@ -258,6 +275,11 @@ void FoodDeliveryController::updateRestaurantStatus()
|
|||||||
listRestaurants();
|
listRestaurants();
|
||||||
std::cout << "Updated Restaurant " << restaurantIterator->second->getName() << " successfully\n";
|
std::cout << "Updated Restaurant " << restaurantIterator->second->getName() << " successfully\n";
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FoodDeliveryController::listRestaurantOrders()
|
void FoodDeliveryController::listRestaurantOrders()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ void RestaurantOwnerMenu::showMenu()
|
|||||||
{
|
{
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
while (isMenuActive)
|
while (isMenuActive)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
int choice;
|
int choice;
|
||||||
util::clear();
|
util::clear();
|
||||||
@@ -35,6 +37,12 @@ void RestaurantOwnerMenu::showMenu()
|
|||||||
isMenuActive = false;
|
isMenuActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << e.what() << std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RestaurantOwnerMenu::handleOperation(int choice)
|
bool RestaurantOwnerMenu::handleOperation(int choice)
|
||||||
|
|||||||
Reference in New Issue
Block a user