Nested Try for a Score Lookup
Nested Try for a Score Lookup
The function scoreAt(const std::vector<int>& scores, int index) is already written: it returns the score at index, or throws a std::out_of_range when there is no such student. A stored score of -1 means "not recorded". Write showScore(const std::vector<int>& scores, int index) with a try INSIDE another try:
- the inner try calls scoreAt; if the score is below 0 it throws a std::invalid_argument with the message Score not recorded; otherwise it prints Score: and the score
- the inner catch handles only std::out_of_range, printing Index problem: and the message
- after the inner try/catch, still inside the outer try, print Lookup finished
- the outer catch handles std::invalid_argument, printing Data problem: and the message
An exception that the inner handler does not match keeps travelling outwards, so the std::invalid_argument skips the inner catch AND the Lookup finished line and lands in the outer handler.
The tests call showScore for several indexes.
Do NOT write a main function.
Expected Output:
Score: 80 Lookup finished Data problem: Score not recorded Index problem: No student at that index Lookup finished
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...