Python Built-in Exceptions Reference
This reference lists all built-in Python exceptions and errors so you can quickly identify and handle runtime problems. It includes the common categories or types of exceptions, the full alphabetical list, and the exception hierarchy so you know which errors inherit from others.The list below refers to the built-in exceptions available in your Python version, currently about 70 items.
Exception categories
- Arithmetic Errors
- I/O and File System Errors
- Lookup and Indexing Errors
- Type and Value Errors
- System level and Runtime Errors
Alphabetical Reference
Following is a list of 70 built-in Python exceptions, although it may vary slightly by version. Press the filter buttons to narrow the table to a category or to search for a specific exception name.
| Exception | Description |
|---|---|
| ArithmeticError | Occurs when a numeric calculation is invalid or fails unexpectedly. |
| AssertionError | Raised when an assert statement’s condition evaluates to false. |
| AttributeError | Occurs when an object lacks the requested attribute or method. |
| BaseException | The root class for all built-in exception types in Python. |
| BaseExceptionGroup | Groups multiple exceptions raised at the same time together. |
| BlockingIOError | Occurs when a non-blocking I/O operation would cause blocking. |
| BrokenPipeError | Raised when writing to a closed pipe or socket connection. |
| BufferError | Raised when a buffer operation cannot be performed properly. |
| BytesWarning | Warning about suspicious or ambiguous bytes or bytearray usage. |
| ChildProcessError | Occurs when a child process encounters an error during execution. |
| ConnectionAbortedError | Raised when a network connection is unexpectedly aborted. |
| ConnectionError | Base class for all exceptions related to connection failures. |
| ConnectionRefusedError | Occurs when a connection attempt is rejected by the target server. |
| ConnectionResetError | Raised when the connection is forcibly closed by the remote peer. |
| DeprecationWarning | Warning that a feature is outdated and will be removed later. |
| EOFError | Raised when input() encounters the end of the input stream. |
| EncodingWarning | Warning about potential problems in encoding or decoding text. |
| EnvironmentError | Raised for OS or environment related failures (same as OSError). |
| Exception | Base class for most errors except system-exit events in Python. |
| ExceptionGroup | Represents multiple exceptions raised together in concurrent code. |
| FileExistsError | Raised when creating a file or directory that already exists. |
| FileNotFoundError | Raised when a requested file or directory cannot be found. |
| FloatingPointError | Raised for errors during floating-point arithmetic operations. |
| FutureWarning | Warning about features that will change in future Python versions. |
| GeneratorExit | Raised when a generator is closed, usually to clean up resources. |
| IOError | Raised for input/output operation failures (same as OSError). |
| ImportError | Raised when an import fails for reasons other than missing module. |
| ImportWarning | Warning about deprecated or problematic import behavior. |
| IndentationError | Raised for incorrect indentation in source code (a SyntaxError subclass). |
| IndexError | Raised when a sequence index is out of range or invalid. |
| InterruptedError | Raised when a system call is interrupted by a signal. |
| IsADirectoryError | Raised when a file operation is attempted on a directory path. |
| KeyError | Raised when accessing a missing key in a dictionary. |
| KeyboardInterrupt | Raised when the user interrupts program execution (e.g., Ctrl+C). |
| LookupError | Base class for lookup-related errors like IndexError and KeyError. |
| MemoryError | Raised when the Python interpreter runs out of available memory. |
| ModuleNotFoundError | Raised when an import fails because the module is not found. |
| NameError | Raised when a variable or name is not defined in the current scope. |
| NotADirectoryError | Raised when a path expected as a directory is not actually one. |
| NotImplementedError | Raised to indicate an abstract method or feature is not implemented yet. |
| OSError | Raised for operating system related errors like file or process failures. |
| OverflowError | Raised when a numeric calculation produces a value too large to handle. |
| PendingDeprecationWarning | Warning that a feature may be deprecated in a future Python release. |
| PermissionError | Raised when an operation lacks permission to access a file or resource. |
| ProcessLookupError | Raised when an operation fails because the target process does not exist. |
| RecursionError | Raised when maximum recursion depth is exceeded during function calls. |
| ReferenceError | Raised when a weak reference points to an object that no longer exists. |
| ResourceWarning | Warning about unclosed system resources like files or network connections. |
| RuntimeError | Raised for generic runtime errors not covered by other exceptions. |
| RuntimeWarning | Warning for non-fatal runtime issues detected during execution. |
| StopAsyncIteration | Raised by asynchronous iterators to signal the end of iteration. |
| StopIteration | Raised to signal that an iterator has no more items to provide. |
| SyntaxError | Raised when Python code contains invalid syntax and cannot parse. |
| SyntaxWarning | Warning about suspicious or deprecated Python syntax in code. |
| SystemError | Raised for internal interpreter errors indicating a bug in Python itself. |
| SystemExit | Raised by sys.exit() to exit the Python interpreter cleanly. |
| TabError | Raised for inconsistent use of tabs and spaces in indentation. |
| TimeoutError | Raised when a blocking operation times out before completion. |
| TypeError | Raised when an operation is performed on an inappropriate data type. |
| UnboundLocalError | Raised when a local variable is referenced before being assigned. |
| UnicodeDecodeError | Raised when bytes cannot be decoded to text using a given encoding. |
| UnicodeEncodeError | Raised when text cannot be encoded to bytes with the specified encoding. |
| UnicodeError | Base class for all Unicode-related encoding and decoding errors. |
| UnicodeTranslateError | Raised when a Unicode translation operation (e.g., str.translate) fails. |
| UnicodeWarning | Warning about potential issues with Unicode text handling. |
| UserWarning | Generic warning category for user-defined warnings in Python code. |
| ValueError | Raised when a function receives an argument of correct type but invalid value. |
| Warning | Base class for warning categories issued during program execution. |
| WindowsError | It was a Windows-specific alias for OSError. |
| ZeroDivisionError | Raised when dividing a number by zero or modulo zero operation. |
Dynamically Get All Python Built-in Exceptions
To programmatically retrieve a complete list of all the built-in Python exceptions or errors, we can utilize the following code snippet.
Get All Built-in Exceptions
import builtins
import inspect
# Get all built-in exceptions in Python
all_exceptions = [name for name, obj in vars(builtins).items()
if inspect.isclass(obj) and issubclass(obj, BaseException)]
print(sorted(all_exceptions))
Hierarchy of Python Built-in Exceptions
The hierarchy of Python’s built-in exceptions illustrates how different exception classes are related and organized. It also highlights the categories these exceptions belong to. Below is the Python built-in exceptions hierarchy:
Exceptions Heirarchy
BaseException
├── BaseExceptionGroup
├── GeneratorExit
├── KeyboardInterrupt
├── SystemExit
└── Exception
├── ArithmeticError
│ ├── FloatingPointError
│ ├── OverflowError
│ └── ZeroDivisionError
├── AssertionError
├── AttributeError
├── BufferError
├── EOFError
├── ExceptionGroup [BaseExceptionGroup]
├── ImportError
│ └── ModuleNotFoundError
├── LookupError
│ ├── IndexError
│ └── KeyError
├── MemoryError
├── NameError
│ └── UnboundLocalError
├── OSError
│ ├── BlockingIOError
│ ├── ChildProcessError
│ ├── ConnectionError
│ │ ├── BrokenPipeError
│ │ ├── ConnectionAbortedError
│ │ ├── ConnectionRefusedError
│ │ └── ConnectionResetError
│ ├── FileExistsError
│ ├── FileNotFoundError
│ ├── InterruptedError
│ ├── IsADirectoryError
│ ├── NotADirectoryError
│ ├── PermissionError
│ ├── ProcessLookupError
│ └── TimeoutError
├── ReferenceError
├── RuntimeError
│ ├── NotImplementedError
│ └── RecursionError
├── StopAsyncIteration
├── StopIteration
├── SyntaxError
│ └── IndentationError
│ └── TabError
├── SystemError
├── TypeError
├── ValueError
│ └── UnicodeError
│ ├── UnicodeDecodeError
│ ├── UnicodeEncodeError
│ └── UnicodeTranslateError
└── Warning
├── BytesWarning
├── DeprecationWarning
├── EncodingWarning
├── FutureWarning
├── ImportWarning
├── PendingDeprecationWarning
├── ResourceWarning
├── RuntimeWarning
├── SyntaxWarning
├── UnicodeWarning
└── UserWarning