Complete a program that reads a vector index as input and outputs the element of a vector of 10 names at the index specified by the input. Use a try block to output the name and a catch block to catch any out_of_range exceptions. When an out_of_range exception is caught, output the message from the exception object and the first element in the vector if the index is negative or the last element if the index is greater than the size of the vector.

Respuesta :

The program segment is an illustration of the try and catch program exceptions

The complete program

The program segment written in C++, where comments are used to explain each action is as follows:

//This opens the try block

   try{

       //This prints the vector element

       cout<<names[index];

   }

   //This opens the catch block

   catch (const std::out_of_range& oor) {

       //This prints the exception

       cerr << "Out of Range error: " << oor.what() << '\n';

 }

Read more about program segments at:

https://brainly.com/question/11623795

ACCESS MORE