← Back to Exceptions
Question 763
Keep Going After a Skipped Guest
Keep Going After a Skipped Guest
The function greeting(const std::string& name) is already written: it returns a welcome message, or throws a std::invalid_argument when the name is empty. Write announce(const std::string& name), which prints the greeting for name on its own line. When greeting throws, catch the std::invalid_argument and print Skipped: followed by its message instead. Either way, print Next on its own line afterwards: a caught exception must not stop the program, and the line after the try/catch runs every time.
The tests call announce for a few names, including an empty one, in order.
Do NOT write a main function.
Expected Output:
Welcome, Ana! Next Skipped: Name is empty Next Welcome, Bo! Next
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.