Skip to main content

Practice ยท 1 of 1

Throw the right exception type

Implement int validate_line(const std::string& line) interpreting the line as a non-negative integer: throw std::invalid_argument for an empty line, a leading '-', or any non-digit; throw std::out_of_range when the parsed value exceeds 100; otherwise return the value.

Difficulty: intermediate

Back to lesson: Practice: Exception practice