Opening Scenario

You're adding a charge_customer(customer_id, amount) function to a billing service. Inside, it will:

  1. Look up the customer
  2. Validate the amount is positive and under their limit
  3. Call the payment gateway (network request, can time out)
  4. Write a ledger row (DB write, can conflict)
  5. Send a receipt email (best effort)

Each step can fail in its own way. Now decisions pile up. Does charge_customer throw on a network timeout, or return a Result? Does an invalid amount raise the same type of error as a gateway decline? Should the email failure bubble up and abort the whole flow, or be swallowed? Who turns these into HTTP 400 vs. 500 vs. 402?

A junior on the team just wrote:

# Python
try:
    charge_customer(cid, amt)
except Exception:
    pass   # we'll fix this later

Two weeks later a customer is double-charged and nobody noticed. This is what an error handling strategy is for — so the answer isn't reinvented case by case.

In the full tutorial

  • Question Progression
  • When to Reach for This

Glossary history

Click dotted jargon to save explanations here.