Unknown Item Error with a Built Message
Unknown Item Error with a Built Message
Create an exception type UnknownItemError that inherits publicly from std::runtime_error. Its constructor takes the item name as a const std::string& and passes the text unknown item: followed by the name up to the base-class constructor, so what() returns that full message without you writing a what() of your own. Then finish priceFor(const std::string& item): the prices for pen and notebook are already there; for any other item throw an UnknownItemError built from the item name.
The tests look up a few items, printing the name, : and the price, or Error: and the message; one test catches UnknownItemError, the other catches it as a std::runtime_error, which works because of the inheritance.
Do NOT write a main function.
Expected Output:
pen: 1.5 Error: unknown item: stapler notebook: 3.25
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...