Skip to content
Sharp

Exceptions · interview question

A bug appears around raising exceptions. What is the strongest first debugging move?

Multiple choiceEasychapter-5-curatedpremiumexceptionsraising-exceptions
python
def ensure_positive(quantity: int) -> None:
    if quantity <= 0:
        raise ValueError("quantity must be positive")
Choose one answer
Answer and explanation

Correct answer

C. Trace one concrete example, inspect the state transitions, and compare them to the intended rule before rewriting anything.

Why

That approach is reliable because it creates evidence. Delaying a broken invariant usually spreads bad data and hides the original mistake.

Test yourself on Exceptions

A free test with instant, explained results. No account needed.

Start free test
All Exceptions questions →