Skip to main content

Checkpoint: Config parser with a field-aware exception

Challenge on lesson: Checkpoint: A Parser That Explains Itself

Implement int parse_config_value(const std::string& content) scanning lines for one starting with value=. Return the parsed non-negative number. Throw a custom ConfigError (deriving from std::runtime_error, carrying the offending line number as a field, exposed via line_no()) when the value is missing, empty, or non-numeric — the exception's what() must read line <N>: <message> with the REAL line number (1-based).

Difficulty: intermediate

Back to lesson: Checkpoint: A Parser That Explains Itself