Skip to main content

Practice · 3 of 3

Debug: The Parser That Crashes the App

CHALLENGE
Difficulty: intermediate+25 XP

ImportProducts throws raw JsonException (and crashes the caller) on malformed input, and silently accepts products with missing names as "". Fix: parse errors surface as InvalidOperationException("bad payload", ex); a missing or empty Name also throws InvalidOperationException with "bad payload" (no exceptions escape other than that type). ``csharp public sealed record Product(string Name, decimal Price); static System.Collections.Generic.List<Solution.Product> ImportProducts(string json); // json: {"products":[{"name":"bolt","price":0.5},{"name":"nut","price":0.2}]} ``

Back to lesson: Practice: JSON Practice: Options, Converters, Boundaries