0PricingLogin
Flask Academy · Lesson

Raise Custom Exception Classes

Define domain errors that map to JSON.

Errors That Speak Your Domain

Numbers like 400 are generic. A custom exception names the real problem, such as a payment that failed or a quota hit.

Subclass an Exception

You start by defining a class that inherits from Exception. This gives you a clear, raisable error of your own.

class PaymentError(Exception):
    pass

All lessons in this course

  1. abort and HTTP Error Codes
  2. Register errorhandler Functions
  3. Raise Custom Exception Classes
  4. Uniform JSON Error Envelopes
← Back to Flask Academy