Code Quality, Error Handling, and Defensive Programming Questions

Writing robust, high-quality code that fails safely. Covers defensive programming, input validation, error handling and fault tolerance, logging for diagnosability, and general engineering-quality standards. Includes anticipating failure modes and making code resilient to bad inputs and unexpected states.

HardTechnical
23 practiced

Design a small set of custom static-analysis checks to detect common defensive-programming anti-patterns that make debugging harder, for example swallowing exceptions, broad try/catch blocks, and empty catch blocks. For each check, explain how you would implement it and give a sample warning message.

HardTechnical
31 practiced

You are developing firmware for an IoT device that sometimes loses power mid-write and ends up with corrupted state. Describe defensive strategies at the software and firmware level to ensure state consistency and recovery: journaling, atomic writes, checksums, transactional updates, wear-leveling, and graceful degradation for the case where the state cannot be repaired.

EasyTechnical
21 practiced

Explain patterns for handling missing or null values in strongly-typed languages like Java and dynamically-typed languages like Python or JavaScript. Include examples of Option/Maybe-style types, exceptions, and sentinel values, and explain when you would use an assertion compared to throwing a recoverable error.

EasyTechnical
29 practiced

A boundary check validates that a value (an index, an offset, a size) falls within the range the code actually handles correctly, and it routinely catches real production bugs before they cause damage. Pick three DIFFERENT kinds of boundary bugs you've seen or can construct realistically, and for each: describe the bug it would cause if unchecked, the specific defensive check you'd add, and a unit test that would catch a regression if the check were later removed.

MediumTechnical
31 practiced

Implement bool add_will_overflow(int32_t a, int32_t b) in C++ that returns true if a + b would overflow a 32-bit signed integer. Do not use a 64-bit type. Include unit tests for edge cases such as INT_MAX + 0, INT_MAX + 1, and negative overflows, and explain your approach.

Unlock Full Question Bank

Get access to all 10 Code Quality, Error Handling, and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.