Exceptions · interview question
What is the healthiest performance judgment around raising exceptions?
Multiple choiceMediumchapter-5-curatedpremiumexceptionsraising-exceptions
def ensure_positive(quantity: int) -> None:
if quantity <= 0:
raise ValueError("quantity must be positive")Answer and explanation
Correct answer
C. Measure before optimizing, then change the part that actually dominates cost instead of guessing from style alone.
Why
Premature optimization is usually weaker than targeted optimization backed by measurement.
Test yourself on Exceptions
A free test with instant, explained results. No account needed.
More Exceptions questions
- Which judgment is strongest when choosing a data shape for try and except?
- Another engineer will maintain this code later. What choice helps the most around try and except?
- A bug appears around try and except. What is the strongest first debugging move?
- What is the healthiest performance judgment around try and except?
- Which explanation would best help the team align on raising exceptions?
- Which move is the best default when try and except become part of this workflow?