Custom Error Hierarchy for App Settings
Custom Error Hierarchy for App Settings
Build a small family of exception classes and a function that throws them:
- AppError inherits from std::runtime_error; its explicit constructor takes a const std::string& message and passes it to the base
- ConfigError and NetworkError both inherit from AppError with the same constructor shape
- std::string loadSetting(const std::string& key): an empty key throws ConfigError("missing key"), the key remote throws NetworkError("server unreachable"), and any other key returns "value of " followed by the key
Because both specific errors are-an AppError, a caller can catch them one by one or catch the base for both. The tests call loadSetting with several keys and print either the returned value, or a label (config problem: , network problem: or app problem: ) followed by what(), one line per key. The second test reads the keys from input, one per line, an empty line meaning an empty key.
Do NOT write a main function.
Expected Output:
value of theme config problem: missing key network problem: server unreachable value of volume
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...