CJCoding With Joseph
15free / daySign inCreate account

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.

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.