# Raising Your Own Exceptions in an API

An API's own rules raise exception classes named for each problem, such as TicketNotFound and StatusChangeNotAllowed, from plain functions that know nothing about HTTP, and @app.exception_handler turns each one into a status code and a JSON body, such as 404 or 409.

![Cheat sheet: Raising Your Own Exceptions in an API](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/7628c1cbe2104586b0c632ea9d69043e.webp)

- Category: FastAPI
- Level: Journeyman
- Tags: 409 Conflict, Custom Exception (python), Exception Handler (fastapi), fastapi, rest-api
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/fastapi-errors-your-own-exceptions-cheat-sheet
