promptdojo_

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
The break is on lines 2, 3, 4, 5, 6, 7 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.