Skip to content
mentoor

Error handling and failure paths in AI code

For engineers

AI code favours the happy path: swallowed errors, silent fallbacks, missing timeouts, unsafe retries, races and forgotten edge inputs

See where you stand

110 questions across four stages: Understand, Apply, Solve and Judge.

Try 5 questions

Practice items, not counted towards your mastery. No account needed.

Check yourself · 1 of 5

An AI-written function returns 0 when the ledger call fails with any exception. What is the main risk?

Choose one answer

Check yourself · 2 of 5

Why is a retry around a payment request dangerous without an idempotency key?

Choose one answer

Check yourself · 3 of 5

Two users book the last seat at the same time and both succeed. Which pattern in the code caused it?

Choose one answer

Check yourself · 4 of 5

An AI function averages a list by dividing the sum by the length. Which input breaks it?

Choose one answer

Check yourself · 5 of 5

A function reduces stock, then charges a card, and the charge fails. What is the best structure?

Choose one answer

Topics

  1. Swallowed errors and silent fallbacks5 min read · Catch-all blocks, default values that hide failures and log-and-continue handlers common in generated code
  2. Timeouts, retries and idempotency5 min read · Network calls with no timeout, retries that send a payment or email twice, and backoff with jitter done right
  3. Race conditions in generated code5 min read · Check-then-act, shared mutable state and missing transactions or locks that agents rarely consider
  4. Edge-case inputs AI code forgets5 min read · Empty lists, nulls, Unicode, time zones, huge numbers and partial data that break the happy path
  5. Partial failure and resource cleanup5 min read · Half-written state after a crash, unclosed connections and files, and cleanup with transactions and finally blocks

Start here

Helps to know first

110 questions · last verified 2026-12