Error Handling and Defensive Programming Questions

Making code robust against bad input and failure: exceptions versus error returns, input validation, guard clauses, graceful degradation, and designing for the unhappy path. Covers where to handle versus propagate errors and how to fail safely without hiding bugs. A recurring probe of production maturity.

HardTechnical
24 practiced

Design a general (non-ML) CI/CD strategy to catch regressions in error handling and observability before they reach production: unit, integration, and contract tests, failure-injection (chaos) tests, gating deploys on test results, and post-deploy observability checks that can trigger an automatic rollback.

MediumTechnical
21 practiced

Given code that catches a broad exception and silently swallows it (try: ... except Exception: pass, or except Exception: print('error'), or a health-check that catches everything and always returns 200), explain why this is dangerous in production, and refactor it: catch specific exception types, log with full context and preserve the stack trace, decide when to re-raise versus recover, instrument a metric, and ensure resource cleanup still happens. Describe the unit tests you would add to prove failures are now visible.

MediumTechnical
30 practiced

Implement a configuration loader (JSON or YAML, in Python or Go) that reads a config file, decodes it into a typed structure, validates required fields with clear, specific error messages (listing every missing or malformed field, not just the first), supports environment-variable overrides and sane defaults, and distinguishes failure modes explicitly (file not found returns defaults, a permission error raises a dedicated exception, a parse error is logged and does not silently succeed). Do not catch a broad Exception. Explain how you'd keep the loader maintainable as the schema evolves.

MediumTechnical
21 practiced

You're leading a team with recurring bugs caused by poor error handling and sparse tests (or balancing shipping new features against investing time in defensive engineering). How would you introduce team-level practices to improve this over a quarter: code-review rules, linters, templates, testing quotas, and a phased rollout that gets buy-in from product? Describe your prioritization framework and how you'd measure success.

MediumTechnical
25 practiced

Design user-facing error messaging for a web or ML-serving application when a request fails (temporary server overload, a validation failure, a corrupted model file, a GPU OOM). The message must be helpful (what happened, what the user can do) without exposing internal details; provide platform variants (mobile vs desktop, screen-reader accessibility) and describe retry UX (automatic retry, a 'try again' button with backoff). For each failure case, give a one-line example of the safe user-facing message and note what extra diagnostic metadata belongs only in the logs.

Unlock Full Question Bank

Get access to all Error Handling and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.