exception handling

I have the following code within which I'm trying to implement exception handling. But it goes into an infinite loop. Could someone tell me what I'm doing wrong? Thanks :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int getMenuOption(void) {
  cout << endl;
  cout << "Menu:" << endl
    << "1 - load eatery information" << endl
    << "2 - save snack cart information" << endl
	<< "3 - save restaurant information" << endl
    << "4 - display eatery information" << endl
    << "5 - add new snack cart" << endl
	<< "6 - add new restaurant" << endl
    << "7 - rate a meal" << endl
    << "8 - change meal cost" << endl
	<< "9 - delete a meal" << endl
    << "10 - show best cart meals" << endl
    << "11 - exit program" << endl;
  cout << "Enter option (1-11): ";

  int value;
  cin >> value;
  try {
  if (cin.fail()) throw 5;
  }
  catch (int e) {
	  cout << e << endl;
  }
  
  return value;
}
I don't see why you are using exceptions here...they are mainly for termination (i.e. stuff you can't recover from).

Anyway, I don't see any loops here...either you aren't hitting enter after your input, or you have a loop somewhere else that is causing the problem.
alright i'll work it out. thanks :)
show me your full code or where you have this function taking place
this is pretty much where I have used it in the code so far.
You must be calling the function in a loop?
Topic archived. No new replies allowed.