User-defined exception
A user-defined exception is a programmer-defined exception type representing 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
- Represents application-specific exceptional conditions that code can raise and handle.
- How deep it goes
- Works through definition, raising, catching, and arguments; defers detailed design of exception subhierarchies.
- Examples
- Uses MyError with a printed message and multiple arguments, plus EmptyStringError in text cleaning.
- What you can do after
- Build it from scratch: define an Exception subclass, raise it, catch it, and decide whether a dedicated type is worthwhile.
Read how The Quick Python Book, Fourth Edition explains user-defined 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 failures at business, API, and user-facing boundaries.
- How deep it goes
- Explains naming, immutable context, wrapping, and cause preservation, without defining exception runtime internals.
- Examples
- Uses data parsing to wrap NumberFormatException as DataProcessingException, with a Python exception-chaining counterpart.
- What you can do after
- Apply it to name domain failures and retain original causes for useful diagnostics.
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.
Related concepts
- exceptionkind of · An exception is a runtime signal or object representing an abnormal condition that interrupts ordinary program flow and may be handled or propagated.
- classkind of · A class is a programming-language construct that defines a type’s structure or behavior and provides a basis for creating or representing objects.
- packageused by · A software package is a named grouping of modules or components, often with related resources and metadata, organized for import, reuse, distribution, or management.
- exception chainingimplemented by · Exception chaining is the preservation of an underlying exception as the cause of a newly raised exception.
- base exception classincludes · A base exception class is a Python class that defines or serves as a superclass for one or more exception types.
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.


