Skip to content
masterclass Buddy

FastAPI · Decorator

@app.exception_handler

@app.exception_handler() registers a function that handles a chosen exception class or HTTP status code. The function receives the request and exception, then returns the response for the error.

Last updated

Syntax

app.exception_handler(exc_class_or_status_code)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • FastAPI
  • Request
  • JSONResponse
  • HTTPException
  • RequestValidationError
  • StarletteHTTPException
  • http_exception_handler
  • request_validation_exception_handler

Source: FastAPI class - FastAPI. Checked 2026-11-03.