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.

HardSystem Design
80 practiced
Design an orchestration pattern for long-running data-preprocessing DAGs where downstream tasks depend on upstream outputs. The system should handle failures, retries, idempotent re-runs, and avoid duplicate work when tasks are restarted. Describe state management and task-level error handling.
HardTechnical
101 practiced
Describe policies and implementation patterns to avoid logging secrets (API keys, tokens, PII) during exception handling. Include example approaches for sanitizing exception messages, secure logging libraries, and how to audit logs for accidental secret leakage.
HardTechnical
79 practiced
You observe increasing resident memory during model training until the process OOMs. Outline a systematic debugging checklist to find memory leaks in Python ML code and list concrete fixes (e.g., detach tensors, delete references, `torch.cuda.empty_cache()`, limiting DataLoader prefetch). Mention tools you'd use.
MediumTechnical
72 practiced
Implement a Python decorator `@retry(exceptions=(requests.exceptions.RequestException,), retries=3, backoff_factor=0.5)` that retries a decorated function on the given exceptions using exponential backoff with jitter. The decorated function may be synchronous and returns its result on success or raises the last exception after retries. Provide the function implementation body (no imports required).
EasyTechnical
99 practiced
Explain Python's try/except/else/finally constructs and best practices for using them in production ML code. In your answer, cover: (1) when to catch broad exceptions (Exception) vs specific exception types, (2) how to preserve the original stack trace, (3) how to ensure resources (files, GPU contexts, DB connections) are cleaned up, and (4) an example scenario: loading a model file and performing a prediction where disk I/O or model-format errors may occur.

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.