CJCoding With Joseph
15free / daySign inCreate account

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.

Hints4 available
Topics:
Exceptions
📥 Auto-Input:
0\n5\n3\n
This input is automatically fed to your program's stdin
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.