Bad Quantity Error Carries the Value
Bad Quantity Error Carries the Value
An exception can carry data about what went wrong. Complete BadQuantityError, which inherits from std::exception and keeps the rejected quantity in its private int quantity:
- a constructor BadQuantityError(int q) that stores q
- const char* what() const noexcept override returning Quantity must be between 1 and 50
- int getQuantity() const returning the stored value
Then write orderBoxes(int quantity): when the quantity is below 1 or above 50 throw a BadQuantityError built from it; otherwise print Ordered , the quantity and boxes.
The tests order several quantities, printing Error: , the message and the rejected value in parentheses after (got when the order fails.
Do NOT write a main function.
Expected Output:
Ordered 10 boxes Error: Quantity must be between 1 and 50 (got 0) Error: Quantity must be between 1 and 50 (got 51) Ordered 50 boxes
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...