Lab 8 - Exception Handling

The purpose of this lab is to add exception handling to the DoubleList class used in Lab 5

Copy your solution for Lab 5 or the posted solution for Lab 5 (lab5.cpp) to a file called lab8.cpp. In lab8.cpp, you are going to add exceptions to the index operator.

First, add an exception class above the DoubleList class definition:

Next, update the index operator to the class. Have a throw list for the index operator that will indicate the function may throw the InvalidIndex exception class. Inside the body for the index operator, if the given index is less than 0 or greater than size - 1, throw an InvalidIndex exception and do NOT print anything out (main will handle printing out an error message now). Otherwise, return the requested element.

Finally, update your main() function to implement the following pseudocode.

allocate a DoubleList with 10 elements (constructor that takes an integer)
for each element in the DoubleList
  prompt the user for element i
  read in element i
end-for
do
  ask the user for an index they wish to access in the DoubleList
  read the user's response into index
  set flag to true
  try
    print out the requested index
  catch InvalidIndex
    output that the index is bad
    set flag to false
while flag is false
This main function will let you test that you have done the InvalidIndex exception correctly. It should keep asking for a new index until you give an index between 0 and 9.

Email your completed lab8.cpp to me.