InterviewStack.io LogoInterviewStack.io

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.

MediumTechnical
29 practiced

Write an idiomatic Go snippet that performs an HTTP GET while respecting a context.Context for timeout and cancellation, wraps any error with call-site context using fmt.Errorf and %w, and then shows how a caller checks the underlying error with errors.Is and extracts a typed error with errors.As. Explain why wrapping with %w rather than string-concatenating the error is useful for callers.

MediumBehavioral
28 practiced

Tell me about a time you found and fixed code that was failing silently (a swallowed exception, an empty catch block, or a missing validation that let a bug reach production repeatedly). Using the STAR structure, describe how you detected the issue, the fix you made, how you convinced others to accept a defensive change that might slow development, and what you did to prevent recurrence.

HardTechnical
47 practiced

A long-running Java service shows intermittent memory growth. Propose code-level and JVM-level strategies to detect and prevent the leak: try-with-resources, being careful with reference types (avoiding accidental strong-reference retention), leak-detection libraries, and how to capture and analyze heap dumps with jmap/jvisualvm. Show a short code example of correct resource management.

HardSystem Design
47 practiced

Design an end-to-end observability and error-monitoring plan for a fleet of services (or an ML-serving microservice architecture spanning gateway, feature store, inference, and cache). Capture structured error events (service, correlation id, stack, severity, user impact), and specify aggregation, deduplication, sampling, and alerting on spikes or SLO breaches. Describe how logs, metrics, and distributed traces correlate to attribute a failure to a specific component and build evidence of causation rather than mere correlation, and how the design avoids alert fatigue.

HardSystem Design
25 practiced

Architect an approach that combines circuit breakers with bulkhead isolation for a set of microservices. Describe where you would place bulkheads (thread pools, connection pools), how you would configure per-client or per-route limits, the emergency fallback behavior when a bulkhead is exhausted, the metrics you would monitor, and how this design prevents healthy requests from starving during a partial failure.

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.