1. Reference to Python Built-in Exceptions or Errors
Being a versatile and dynamically typed language, Python programming provides a robust error-handling mechanism through the use of built-in exceptions. These exceptions are events or errors that occur during the program execution, and due to a rich set of built-in exceptions, Python handles different scenarios efficiently. In this tutorial, we will provide you with a list of all the built-in exceptions or errors in Python programming. Moreover, we will also provide you with a code snippet that you may utilize to acquire the complete and up-to-date list of all the built-in exceptions in Python programming. Lastly, we will also share the heirarchy of the Python built-in exceptions or errors.
2. Search Ultimate Reference For Python Built-in Exceptions
The table below comprises all the built-in exceptions or errors in Python language and serves as an ultimate guide or reference to the developers. You can use the input field to search for any exception or error from the table. These built-in exptions of Python programming are listed alphabetically.
2.1. Alphabetical Reference
|This exception is raised when an error occurs in numeric calculations.
|This exception is raised when an assert statement fails.
|When an attribute reference or assignment fails, this exception is raised.
|The base class for all built-in exceptions, providing common functionality for Python error handling.
|A group of exceptions that allows handling multiple exceptions within a single except clause.
|When an I/O operation is blocked on an object like a socket or pipe, this exception is raised.
|When trying to write to a pipe that has been closed by the other end, this exception is raised.
|This exception is raised when a buffer-related operation fails.
|This exception is related to a warning about bytes and bytearray operations.
|When an error occurs in a child process, this exception is raised.
|When the connection is aborted by the network, this exception is raised.
|This is the base class for exceptions related to connections.
|This exception is raised when a connection attempt is refused by the peer.
|When a connection is reset by the peer, this exception is raised.
|When there are features that are no longer needed and may be deprecated in the future, this exception is raised.
|This exception is raised when the input() function hits an "end of file" condition (EOF).
|This exception is a warning about issues related to Unicode encoding.
|It is a base class for the exceptions that can occur outside the Python system.
|This is the base class for all built-in exceptions in Python language.
|A group of exceptions, but not a built-in exception in Python.
|While trying to create a file or directory that already exists, this exception is raised.
|While requesting a file or directory but cannot find it, this exception is raised.
|This exception is raised when a floating point operation or calculation fails.
|This exception is a warning that is raised about a feature of Python that will be deprecated in the future.
|When a generator is closed with the close() method, this exception is raised.
|This is the base class for the I/O errors.
|This exception is raised when we import a module that does not exist.
|When there is a deprecated feature related to imports, this exception raises a warning.
|The base class for syntax errors related to incorrect indentation.
|This exception is raised when a sequence subscript is out of range.
|When a system call is interrupted by an incoming signal, this exception is raised.
|When a file operation is requested on a directory, this exception is raised.
|This exception is raised when a key does not exist in a Python dictionary.
|This exception is raised when the user presses interrupts the program execution usually pressing CTRL+C.
|When a key or index is not found, this exception is raised.
|When an operation runs out of memory, this exception is raised.
|While trying to find a module that does not exist, this exception is raised.
|While trying to find a variable that does not exist, this exception is raised.
|This exception is raised when an operation is requested on something that is not a directory.
|This exception is raised when an abstract method that needs to be implemented in an inherited class is not actually implemented.
|The base class for operating system-related errors
|When the result of an arithmetic operation is too large, this exception is raised.
|When a module is using a deprecated feature, but is still allowed for now, this exception is raised.
|While trying to perform an operation without necessary permissions, this exception is raised.
|While looking at a process and the operation fails, this exception is raised.
|This exception is raised when the maximum recursion depth is reached.
|This exception is raised when a weak reference proxy is used to access an object that does not exist.
|When there is a warning related to resource usage, this exception is raised.
|A generic runtime error that does not fall into any specific category.
|For runtime warnings, this exception is raised.
|This exception is raised by an asynchronous iterator's __anext__ method to signal the end of the iteration.
|To tell the end of the iteration in a regular iterator, this exception is raised.
|This exception is raised when a syntax error occurs during program execution.
|When the syntax is deprecated and other language-specific issues occur, this exception is raised.
|When there is an internal error detected by the interpreter, it raises this exception.
|This exception is raised by the sys.exit() function to tell the interpreter should exit.
|This exception is raised when indentation contains inconsistent use of tabs or spaces.
|When an operation times out, this exception is raised.
|When an operation is performed on an object of an inappropriate type, this exception is raised.
|An exception of this type is raised when a local variable is referenced before it has been assigned a value.
|This exception is raised when decoding a Unicode-related encoding fails.
|This exception is raised when encoding a Unicode-related encoding fails.
|The base class for all Unicode-related errors.
|When a Unicode translation problem occurs, this exception is raised.
|This exception is raised for Unicode-related warnings.
|For user-generated warnings, this exception is raised.
|When a function receives an argument of the correct type but an invalid value, this exception is raised.
|The base class for warning categories exceptions.
|This exception is raised when a Windows-specific error occurs.
|This exception is raised when the second operand of a division or modulo operation is zero.
3. 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.
Get All Built-in Exceptions
# Get all built-in exceptions or errors import builtins # Get all attributes of the builtins module all_attributes = dir(builtins) # Filter out only the attributes that are classes and are exceptions exceptions = [ attr for attr in all_attributes if isinstance(getattr(builtins, attr), type) and issubclass(getattr(builtins, attr), BaseException) ] # Print the list of exception names for exception in exceptions: print(exception)
4. Heirarchy of Python Built-in Exceptions
The heirarchy of the built-in Python exceptions or errors shows that how the exceptions are related to each other. Further the Python built-in exceptions heirarchy dipicts different categories in which these are divided. See the Python built-in exceptions heirarchy below:
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
5. Reference Links
To compile this ultimate and up-to-date reference or guide of all the Python built-in exceptions or errors, we consulted and gathered data from the sources below.