Skip to content
Sharp

Exceptions · interview question

What does a strong engineer do when reasoning through raising exceptions code?

Multiple choiceMediumchapter-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

B. Narrate the data shape, the state changes, and the exact rule order step by step.

Why

Interviewers often use simple code to test whether you can reason through execution without bluffing.

Test yourself on Exceptions

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

Start free test
All Exceptions questions →