CJCoding With Joseph
15free / daySign inCreate account

Empty Name Error Class

Create your own exception type EmptyNameError that inherits publicly from std::exception (header <exception>) and overrides what() to return the text Player name cannot be empty. The override must have exactly the base signature, const char* what() const noexcept override. Then write registerPlayer(const std::string& name): when name is empty it throws an EmptyNameError; otherwise it prints Registered followed by the name.

Because your class derives from std::exception, a handler for const std::exception& catches it too: the first test catches EmptyNameError by name, the second catches it through the base class; both print Error: and the message.

Do NOT write a main function.

Expected Output:

Registered Ana
Error: Player name cannot be empty
Registered Bo

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
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.