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.

MediumTechnical
84 practiced
Write a Python decorator `exception_mapper(http_status_map: dict)` for a Flask-like endpoint that maps exception types to HTTP status codes and JSON bodies. The decorator should catch exceptions raised by the handler, look up the status, and return a JSON dict with keys `error`, `message`, and `code` while preserving the original exception message. Sketch the implementation (focus on mapping and response creation).
HardTechnical
106 practiced
Design metrics and alerts to proactively detect silent failures in model outputs, such as constant predictions, predictions with NaNs, or collapsed probability distributions. Include how you'd distinguish between model bugs and upstream data issues, and describe alert thresholds and on-call playbook steps.
EasyTechnical
75 practiced
You're writing shell scripts to prepare data for training. Explain the role of `set -e`, `set -u`, and `trap` for error handling in bash. Provide an example snippet that ensures the script exits on errors, treats unset variables as errors, and performs cleanup (deleting a temporary working directory) even when interrupted.
EasyTechnical
96 practiced
When should you use assertions (assert statements) versus explicit input validation in production ML code? Discuss the differences in intent, runtime behavior (e.g., python -O), and recommended uses (developer vs user input checks). Provide a concise guideline for an ML engineer.
MediumTechnical
73 practiced
Describe a testing strategy to make ML pipelines deterministic for unit tests: how to mock random seeds, external data sources, long-running training, and hardware-specific behavior (GPUs). Provide concrete techniques and code-testing patterns you'd use.

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.