Validate a Record with Three Error Types
Validate a Record with Three Error Types
Build four exception classes and one validator from scratch:
- RecordError inherits from std::runtime_error; its explicit constructor takes a const std::string& message and passes it on
- NameError, AgeError and EmailError each inherit from RecordError with the same constructor shape
- void validateRecord(const std::string& name, int age, const std::string& email) checks the fields IN THIS ORDER and throws at the first problem: an empty name throws NameError("name is empty"); an age below 0 or above 150 throws AgeError with the text age out of range: and the age; an email without an @ throws EmailError with the text email has no @: and the email. A record that passes all three prints valid: and the name.
The tests call validateRecord with several records and print either the valid line or a label (name problem: , age problem: , email problem: or record problem: ) followed by what(), one line per record.
Do NOT write a main function.
Expected Output:
valid: Ada name problem: name is empty age problem: age out of range: 200 email problem: email has no @: ada.example.com
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...