Translate a Low-Level Error into a Sensor Error
Translate a Low-Level Error into a Sensor Error
The provided readRaw(int slot) throws a std::out_of_range for a slot that does not exist. Callers should not have to know that detail, so catch it and throw your own error in its place (this is translating, not rethrowing):
- SensorError inherits from std::runtime_error; its explicit constructor takes a const std::string& message and passes it on
- double readSensor(int slot): calls readRaw(slot) and returns its reading; if that throws std::out_of_range, throw SensorError with the text sensor , the slot number and unavailable instead
The tests read slot numbers from input, one per line, and print reading: and the value, or what() of the SensorError. They also catch std::out_of_range separately and print raw error escaped, which must never appear. For the first test the input is 0, 5, 3.
Do NOT write a main function.
Expected Output:
reading: 10.5 sensor 5 unavailable reading: 42
= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...