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.

EasyTechnical
29 practiced

Explain the standard log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) and give a concrete example of what belongs at each level in a backend or ML-serving context (for example: DEBUG for per-batch loss, WARNING for a missing optional feature, ERROR for a failed model load). Discuss how log-level choice affects storage volume and alerting strategy in production.

HardTechnical
31 practiced

A nightly batch job (or a multi-stage data-preprocessing DAG) processes millions of records and occasionally crashes mid-run. Design a resume/restart mechanism so that on restart, processing continues from the last consistent checkpoint without duplicating side effects on already-processed records. Discuss checkpoint granularity, idempotent re-runs, transactional updates, state management for a DAG with dependent tasks, and the throughput-versus-checkpoint-frequency trade-off.

EasyTechnical
25 practiced

Implement safe_divide(a, b) that defensively handles division by zero, non-numeric inputs, and values that would produce inf/nan. Return either a structured result ({ok, value, error}) or raise a clear exception, and explain the trade-off between the two designs for callers. Include unit tests for the normal, zero-divisor, non-numeric, and extreme-value cases.

MediumTechnical
39 practiced

Implement and test defensive integer-overflow handling: write a function that adds (or multiplies) two signed integers and either raises/returns an explicit error on overflow, or (in a language like Go) safely parses a string to an integer and returns an explicit error on overflow rather than wrapping silently. Cover boundary and negative-value test cases, and explain why detecting overflow explicitly is safer than letting it wrap.

HardTechnical
43 practiced

Design a chaos-engineering game-day plan focused on error handling and defensive programming (for a general backend service or a model-serving cluster): specific experiments (network latency, connection resets, a slow DB, OOM-kill, node failure, corrupted artifacts), blast-radius controls and safety caps, success criteria tied to SLOs, an automated test harness, and how findings become tracked, actionable work items.

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.