InterviewStack.io LogoInterviewStack.io

Error Handling and Defensive Programming Questions

Covers designing and implementing defensive, fault tolerant code and system behaviors to prevent and mitigate production failures. Topics include input validation and sanitization, null and missing data handling, overflow and boundary protections, exception handling and propagation patterns, clear error reporting and structured logging for observability, graceful degradation and fallback strategies, retry and backoff policies and idempotency for safe retries. Also address concurrency and synchronization concerns, resource and memory management to avoid exhaustion, security related input checks, and how to document and escalate residual risks. Candidates should discuss pragmatic trade offs between robustness and complexity, show concrete defensive checks and assertions, and describe test strategies for error paths including unit tests and integration tests and how monitoring and operational responses tie into robustness.

MediumTechnical
0 practiced
Describe a layered defense approach against SQL injection in a service that uses both raw queries and an ORM. Include parameterized queries, input validation, least-privilege database users, and runtime monitoring. Provide practical examples of checks you would implement at each layer.
MediumTechnical
0 practiced
Given this Java code snippet prone to race conditions: `if (cache.get(key) == null) { value = load(); cache.put(key, value); } return cache.get(key);`, explain the data race and implement a thread-safe solution with minimal blocking and good throughput, describing trade-offs.
MediumTechnical
0 practiced
Create a plan for regression tests that verify fallback behavior when a cache tier fails. Include test orchestration steps, how to inject cache failures in test and staging, and what assertions ensure both correctness and acceptable performance degradation.
MediumTechnical
0 practiced
Implement a `safeDivide(a, b)` function in Python that defensively handles division by zero, non-numeric inputs, and large floats that could produce `inf` or `nan`. Return a structured result like `{ok: bool, value: float|null, error: string|null}` and explain how this design simplifies callers compared to raising exceptions.
MediumTechnical
0 practiced
You find a race condition in Java where two threads sometimes increment a counter twice for the same logical event leading to duplicate billing. Given a short description of current code that uses `if (!map.containsKey(id)) map.put(id, value)`, explain the bug and propose multiple fixes, trade-offs and how to unit-test the fix.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.