C++ Intermediate · exercise 05
Error handling strategies
Return an optional instead of throwing for an expected parsing failure.
C++ Intermediate lesson 05Guided steps
- 1.Return std::optional<double> from parseSpeed: empty when the text is not a number.
- 2.Catch the conversion failure inside the function; the caller should not need a try block.
- 3.Print the value when present and an error line when not.
Your code
Your code is saved in this browser after every run and restored next time.