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
You're reviewing a Python function used in model training:
python
def train_model(data):
    try:
        preprocess(data)
        model.fit(data)
    except Exception:
        print('error')
Explain why catching 'Exception' and printing a message is problematic for production ML systems. Describe concrete refactoring steps to make this code production-ready: specify which exception types to catch, how to log and preserve stack traces, when to re-raise, how to instrument metrics, and how to ensure resource cleanup (e.g., GPUs, temp files).
EasyTechnical
0 practiced
Given a Python preprocessing module with functions named m1 and m2, lots of nested loops, no docstrings, and mixed responsibilities (parsing, cleaning, feature extraction), propose a refactor plan to improve readability and maintainability. Cover renaming, extracting smaller functions, adding docstrings and type annotations, creating a module layout, and how you'd verify behavior didn't change during refactor (tests/mocks).
MediumTechnical
0 practiced
Write a Python decorator `warn_if_slow(threshold_ms)` that times a function execution, logs a warning if it exceeds the threshold (including function name and duration), preserves the wrapped function's metadata using functools.wraps, and emits a metric counter. Provide code and explain how you'd avoid high overhead for functions called in tight loops.
HardTechnical
0 practiced
Design a fuzz-testing harness for an NLP model to discover inputs that cause crashes, hangs, or silent failures. Include mutation strategies (insertion, deletion, unicode, control chars), oracle definitions for detecting abnormal behavior (exceptions, timeouts, anomalous outputs), resource/time limits per test, de-duplication of findings, and reporting. Explain how to scale fuzzing across many seeds and integrate into CI.
HardSystem Design
0 practiced
Design a distributed circuit-breaker mechanism to prevent cascading failures from model-serving instances to downstream systems (e.g., billing). Define states (closed/open/half-open), failure thresholds in time windows, warm-up/half-open probes, and a strategy to synchronize state across instances without a single point of failure. Discuss pros/cons of local vs global breaker state and provide algorithms for fail-open vs fail-closed trade-offs.

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.