# Custom Exception

*noun*

say it: **“KUS-tum ek-SEP-shun”** **/ˈkʌstəm ɪkˈsɛpʃən/**

An error type you make yourself by inheriting from Exception, named for exactly the problem it reports, such as OutOfStockError.

## What is a **custom exception**?

A **custom exception** is your own error type, made by inheriting from `Exception`. Its name tells exactly what went wrong.

```python
class OutOfStockError(Exception):
    pass

def buy(stock):
    if stock == 0:
        raise OutOfStockError("Sorry, sold out")
```

## In a sentence

- “A **custom exception** lets the caller catch sold-out items apart from every other error.”
- “The shop raises a **custom exception**, OutOfStockError, when an item is sold out.”

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 19, 2026

## In other subjects

- [Custom Exception in C#](https://www.ask-codey.com/glossary/custom-exception-c-sharp)
- [Custom Exception in Java](https://www.ask-codey.com/glossary/custom-exception-java)

Source: https://www.ask-codey.com/glossary/custom-exception
