Last Updated: May 22, 2026
Built-in exceptions like ValueError and KeyError cover common cases, but they say nothing about your domain. When a payment fails or a cart is empty, raising Exception("payment failed") works, but callers can't catch that without also catching every other generic error. Custom exceptions are how you give errors a meaningful name and shape that fits your application. This lesson covers what custom exceptions are, how to design a small hierarchy for an e-commerce app, how to attach context to them, and the conventions to follow so the result feels Pythonic.