InterviewStack.io LogoInterviewStack.io

Error Handling and Code Quality Questions

Focuses on writing production quality code and scripts that are defensive, maintainable, and fail gracefully. Covers anticipating and handling failures such as exceptions, missing files, network errors, and process exit codes; using language specific constructs for error control for example try except blocks in Python or set minus e patterns in shell scripts; validating inputs; producing clear error messages and logs; and avoiding common pitfalls that lead to silent failures. Also includes code quality best practices such as readable naming and code structure, using standard libraries instead of reinventing functionality, writing testable code and unit tests, and designing for maintainability and observability.

EasyTechnical
0 practiced
Implement a Python function safe_load_json(path, default=None) that attempts to read and parse a JSON file. Requirements:
- Use only the Python standard library (open, json).- If the file does not exist, return default without raising an exception.- If the file contains invalid JSON, log an informative message and return default.- Ensure the file is always closed and no resource leaks occur.
Example starter:
python
def safe_load_json(path, default=None):
    # your code here
    pass
Provide the implementation and briefly explain how your code avoids silent failures and ensures testability.
MediumTechnical
0 practiced
Design a consistent error response schema for HTTP APIs used both by external clients and internal services. Requirements:
- Include correlation id, machine-readable error code, human message, optional field-level validation details, and suggested next steps.- Describe the mapping of common situations to HTTP status codes (validation error, auth failure, transient downstream failure, rate limit).- Provide a JSON example of an error payload for a validation failure.
Explain how you would version the schema and ensure backward compatibility.
HardTechnical
0 practiced
Design and implement (or provide pseudocode for) a thread-safe retry queue in Java that accepts Runnable tasks, retries failed tasks up to N times with backoff, and records failure metrics (attempts, last error). Requirements:
- Support configurable concurrency level.- Ensure that permanent failures (after max attempts) are logged and exposed via a metrics endpoint.- Avoid deadlocks and ensure graceful shutdown drains or persists the queue.
Explain choices for task persistence vs in-memory only and how to handle poison messages.
HardBehavioral
0 practiced
As a senior engineer, you need to convince product leadership to allocate two sprints for fixing a class of silent failures that cause occasional data inconsistencies. How would you present the case (metrics, risk, user impact, proposed scope), and what success criteria would you propose to show the investment paid off?
HardTechnical
0 practiced
Design a taxonomy for application-layer errors and explain how you would map them to HTTP status codes and internal handling actions. Include at least five categories (e.g., validation, auth, rate-limit, dependency-failure, internal-bug) and show example mappings and why these mappings help automated handlers and dashboards.

Unlock Full Question Bank

Get access to hundreds of Error Handling and Code Quality interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.