Custom exception
A custom exception is a programmer-defined exception type that represents an application-specific error or abnormal condition.
The Quick Python Book, Fourth Edition
A custom exception is a programmer-defined exception class representing an application-specific abnormal condition.
- How it is used
- Distinguishes application-specific conditions for exception handling and library interfaces.
- How deep it goes
- Demonstrates definition, raising, catching, and argument access; outlines custom exception hierarchies without developing them in detail.
- Examples
- Uses MyError with message and tuple arguments, plus EmptyStringError in a text-cleaning function and package.
- What you can do after
- Build custom exception classes from scratch, raise and catch them, and access their arguments.
Read how The Quick Python Book, Fourth Edition explains custom exception →
The Art of Code
A custom exception is an application-defined exception type whose name and structure represent a specific failure condition.
- How it is used
- Translates technical failures into meaningful domain errors at business, API, or user-facing boundaries.
- How deep it goes
- Demonstrates defining and throwing custom exceptions, including immutable captured data and preservation of the original cause.
- Examples
- Uses data parsing failures and invalid order IDs to illustrate named exceptions.
- What you can do after
- Build a custom exception from scratch to name a failure and preserve its original cause.
Python How-To
A custom exception is a programmer-defined exception type used to represent application-specific error conditions.
- How it is used
- Uses named, package-specific failures to communicate application conditions and support callers handling library errors.
- How deep it goes
- Explains inheritance, package hierarchies, custom messages, __str__, raising, catching, and documentation, without detailing exception internals.
- Examples
- Demonstrates TaskierError, FileExtensionError, CSV validation, upload_file, and custom handling for tasks.csv and tasks.docx.
- What you can do after
- Build package-specific exception hierarchies, raise informative failures, catch named conditions, and document possible exceptions.
Also covered in
- The Well-Grounded Python Developer: How the pros use Python and Flask
- Python Workout: 50 ten-minute exercises
- Python Workout, Second Edition
- The Well-Grounded Rubyist, Fourth Edition
What to know first
- exceptionAn exception is a runtime signal representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- ValueErrorValueError is a built-in Python exception raised when an operation receives an argument of an appropriate type but an inappropriate value.
- floating-point arithmeticFloating-point arithmetic is numerical computation using finite-precision representations of real numbers, which can introduce rounding and range errors.
- taxA tax is a compulsory financial charge imposed by a government on income, transactions, property, or other taxable bases.
Related concepts
- exceptionkind of · An exception is a runtime signal representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- classkind of · A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating instances.
- packageused by · A package is a named unit for grouping related software code and resources, serving as a namespace, compilation or import unit, or distributable bundle.
- base exception classincludes · A base exception class is a Python class that defines or serves as a superclass for one or more exception types.
- exception chainingimplemented by · Exception chaining is the preservation of an underlying exception as the cause of a newly raised exception.
Questions about custom exception
What is custom exception?
A custom exception is a programmer-defined exception type that represents an application-specific error or abnormal condition.
Which Manning books explain custom exception?
The Quick Python Book, Fourth Edition, The Art of Code and Python How-To.
What should I know before learning custom exception?
Manning books that teach custom exception usually introduce exception, ValueError, floating-point arithmetic and tax first.
What kinds of custom exception are there?
Kinds of custom exception include base exception class.
What is custom exception a kind of?
Custom exception is a kind of exception. An exception is a runtime signal representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


