Raising errors — making your code fail loudly on purpose — step 6 of 9
Claude shipped this and a teammate spent two days debugging a "missing
data" bug. validate_order calls int(qty) which raises ValueError
on bad input, the except: pass swallows it, and the function falls
through to return None. The caller has no idea anything went wrong.
Replace the try/except block so bad input fails loudly with a
raise ValueError("qty must be positive"). The call site already
has the right try/except to print the message.
Expected output:
qty must be positive
Claude shipped this and a teammate spent two days debugging a "missing
data" bug. validate_order calls int(qty) which raises ValueError
on bad input, the except: pass swallows it, and the function falls
through to return None. The caller has no idea anything went wrong.
Replace the try/except block so bad input fails loudly with a
raise ValueError("qty must be positive"). The call site already
has the right try/except to print the message.
Expected output:
qty must be positive
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.