Hello. I am trying to do a try.. catch statement and where there is exception error thrown, i want it to go back to the beginning. I have done the following, but I know I have made a mistake somewhere, but am stumped. Please assist me here
here is the code :
Code:
#include <iostream>
using namespace std;
void printList(short list[]);
int main()
{
short n[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int index=0, value;
printList(n);
while (index != -1)
{
try
{
cout << "Enter array index (0..9) to update (-1 to quit): ";
cin >> index;
if (index > 10)
throw 1;
else if (index == -1)
break;
}
catch (int index)
{
cout << "Exception thrown" << endl;
}
cout << "Enter new value: ";
cin >> value;
n[index] = value;
printList(n);
}
return 0;
}
void printList(short list[])
{
cout << "List: ";
for (int i=0; i<10; i++)
cout << list[i] << " ";
cout << endl;
}
thank you all !