custom exception
An exception class you define yourself, usually in two lines by subclassing Exception, to name an error specific to your program.
In more detail
class EmptyDataError(Exception): pass is enough. It earns its place when callers need to catch your error separately from built-in ones; otherwise reuse ValueError or another built-in.
Example
class EmptyDataError(Exception):
passRelated terms
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- inheritance — Declaring one class or type as a specialised version of another, so it receives the parent's members and can be used wherever the parent is expected.
- raise statement — The statement that signals an error by creating and throwing an exception, as in raise ValueError("width must be positive").
Taught in
- Raising, And Writing Your Own Exception — Hands-on Python: Complete Video Course & Book
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep