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
In Java, write a method String getNormalizedEmail(User user, String fallback) that safely returns the lowercase email of a possibly-null nested object (user.getProfile().getContact().getEmail()). Requirements:
- Do not throw NullPointerException; return the fallback if any element is null or empty.- Prefer standard Java idioms (Optional or defensive checks) and explain the trade-offs.
Provide the implementation and justify when to favor Optional vs. defensive null checks in a codebase.
MediumTechnical
0 practiced
Design a retry strategy for client-side requests that includes exponential backoff, jitter, maximum attempts, and integration with a circuit breaker. Provide pseudocode or a function signature and explain how you would avoid the thundering herd problem and protect downstream services under load.
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.
MediumTechnical
0 practiced
A downstream service your web app depends on has become slow and intermittently unavailable. Describe a plan to gracefully degrade user experience while protecting your service: include immediate mitigation steps, code-level strategies (caching, fallbacks), circuit-breakers, and what user-facing messages you would show. Prioritize approaches and explain trade-offs.
MediumTechnical
0 practiced
Case study: a scheduled nightly job silently stopped processing halfway through and continued to report success. You have a few lines of logs:
- "[23:11] starting batch"- "[23:12] processed 1,000 records"- "[23:13] processed 2,000 records"- "[23:13] finished"
Describe how you would investigate root cause, provide immediate mitigation, and propose long-term fixes including observability and test changes to prevent recurrence.

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.