Bird
0
0

What happens if an exception is raised inside the lifespan context manager before the yield statement?

medium📝 component behavior Q5 of 15
FastAPI - Middleware and Hooks
What happens if an exception is raised inside the lifespan context manager before the yield statement?
AException is ignored and app starts anyway
BApp starts normally but shutdown code is skipped
CApp startup fails and the exception propagates
DShutdown code runs immediately
Step-by-Step Solution
Solution:
  1. Step 1: Analyze exception before yield

    If an error occurs before yield, startup is interrupted and app does not start.
  2. Step 2: Understand exception propagation

    The exception propagates up, preventing app startup.
  3. Final Answer:

    App startup fails and the exception propagates -> Option C
  4. Quick Check:

    Exception before yield stops startup [OK]
Quick Trick: Errors before yield stop app startup [OK]
Common Mistakes:
MISTAKES
  • Thinking app starts despite errors
  • Assuming shutdown code runs on startup error
  • Ignoring exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes