QuizzesError Handling — Custom Exceptions & Handlers — Concept Check
intermediate
fastapi

Error Handling — Custom Exceptions & Handlers — Concept Check

Questions on Error Handling — Custom Exceptions & Handlers. Raise domain exceptions from services; @app.exception_handler converts them to HTTP responses in one place. Override the validation handler for a consistent error envelope, and never leak stack traces.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Error Handling — Custom Exceptions & Handlers — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A service raises a `StudentNotFound` exception. What HTTP status code will the client receive?

    • A404
    • B400
    • C500
    • D422
  2. 2.You want to add a new domain exception for `CourseFull`. What must you do to ensure proper error handling?

    • AModify all routers to handle the new exception
    • BOnly create a new exception class
    • CCreate an exception class and add it to the translation table
    • DOverride the default HTTPException handler
  3. 3.A client receives a 500 error with a reference ID. What is the likely cause?

    • AThe client sent a malformed request
    • BA validation error was detected
    • CAn unhandled exception occurred
    • DA domain exception was raised
  4. 4.When a `RequestValidationError` occurs, how is the error response structured?

    • AIt uses a standard JSON envelope with error details
    • BIt returns a plain text response
    • CIt uses a different envelope for each validation error
    • DIt leaks the stack trace to the client
  5. 5.A developer believes that raising HTTP exceptions directly in services is the best practice. Why is this incorrect?

    • AIt simplifies error handling
    • BIt ensures consistent error responses
    • CIt couples business logic to HTTP
    • DIt reduces the need for exception handlers
  6. 6.What happens if you don't add a new domain exception to the translation table?

    • AThe app crashes
    • BThe client receives a 500 status code
    • CThe exception is ignored
    • DThe client receives a 400 status code
  7. 7.A service raises a `SeatLimitReached` exception. What should the exception handler return?

    • AA 500 status code with a stack trace
    • BA 404 status code with error details
    • CA 422 status code with validation errors
    • DA 409 status code with error details
  8. 8.Why is it important to never leak stack traces in error responses?

    • AIt provides more information to the client
    • BIt is required by HTTP standards
    • CIt prevents exposing sensitive information to attackers
    • DIt ensures faster error resolution