Comprehensive summary of Python built-in exception types

Built-in exception base class

In Python, all exceptions must be an instance of a class derived from BaseException. Two unrelated exception classes created by subclassing are never equivalent, even if they have the same name.

The following exceptions are mainly used as base classes for other exceptions.

BaseException: The base class of all exceptions

Exception (focus on mastering)

All built-in non-system exit exceptions are derived from this class. All user-defined exceptions should also have no intention of starting from this category.

ArithmeticError

This base class is used to derive built-in exceptions raised for various arithmetic errors: OverflowError, ZeroDivisionError, FloatingPointError.

BufferError

It will be raised when the operation related to the buffer cannot be performed.

LookupError

This base class is used to derive the exception that is raised when the key or index used by the mapping or sequence is invalid: IndexError, KeyError

Hierarchy of built-in exceptions

BaseException The base class of all exceptions
+- - SystemExit interpreter requests to exit
+- - KeyboardInterrupt user interrupt execution(Usually input^C)+--GeneratorExit generator(generator)An exception occurs to notify the exit
+- - Exception base class for general errors
+- - StopIteration iterator has no more values
+- - StopAsyncIteration must pass the asynchronous iterator object__anext__()Method fired to stop iteration
+- - ArithmeticError The base class for all numerical calculation errors
|+- - FloatingPointError floating point calculation error
|+- - OverflowError Numerical operation exceeds the maximum limit
|+- - ZeroDivisionError division(Or modulo)zero(All data types
+- - AssertionError Assertion statement failed
+- - AttributeError object does not have this attribute
+- - BufferError is raised during operations related to the buffer
+- - EOFError has no built-in input,EOF mark reached
+- - ImportError Import failed
|+- - ModuleNotFoundError Module not found
+- - LookupError base class for invalid data query
|+- - IndexError does not have this index in the sequence(index)|+--There is no such key in the KeyError map
+- - MemoryError Memory overflow error
+- - NameError is not declared, initialized object
|+- - UnboundLocalError access to uninitialized local variables
+- - OSError operating system error,
|+- - The BlockingIOError operation sets the blocking object as a non-blocking operation
|+- - ChildProcessError The operation on the child process failed
|+- - ConnectionError is the base class for connection-related exceptions
||+- - BrokenPipeError writes on a socket that has been closed for writing
||+- - ConnectionAbortedError The connection attempt was aborted by the peer
||+- - ConnectionRefusedError The connection attempt was rejected by the peer
||+- - ConnectionResetError The connection was reset by the peer
|+- - FileExistsError creates an existing file or directory
|+- - FileNotFoundError requests a file or directory that does not exist
|+- - InterruptedError system call was interrupted by input signal
|+- - IsADirectoryError requested file operation on the directory
|+- - NotADirectoryError requested a directory operation on something that is not a directory
|+- - PermissionError to run the operation without access permissions
|+- - ProcessLookupError process does not exist
|+- - TimeoutError system function timed out at the system level
+- - ReferenceError weak reference attempts to access an object that has been garbage collected
+- - RuntimeError General runtime error
|+- - NotImplementedError method not yet implemented
|+- - RecursionError The interpreter has detected that the maximum recursion depth has been exceeded
+- - SyntaxError Python syntax error
|+- - IndentationError Indentation error
|+- - TabError Tab and spaces mixed
+- - SystemError General interpreter system error
+- - TypeError invalid operation on type
+- - ValueError passed an invalid parameter
|+- - UnicodeError Unicode related errors
|+- - UnicodeDecodeError Unicode decoding error
|+- - UnicodeEncodeError Unicode encoding error
|+- - UnicodeTranslateError Unicode conversion error
+- - Warning base class
+- - DeprecationWarning Warning about deprecated features
+- - PendingDeprecationWarning A warning that the semantics of the structure will change in the future
+- - RuntimeWarning Suspicious operating behavior warning
+- - SyntaxWarning Suspicious syntax warning
+- - UserWarning User code generated warning
+- - FutureWarning Base class for warnings about deprecated features
+- - The base class for warnings that may go wrong when the ImportWarning module is imported
+- - UnicodeWarning is the base class for Unicode-related warnings
+- - BytesWarning The base class for warnings related to bytes and bytearray
+- - ResourceWarning is the base class for warnings related to resource usage

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Comprehensive summary of Python built-in exception types
Summary of logarithm method in Python
A summary of 200 Python standard libraries!
Summary of Python calling private attributes
Summary of common operations of Python time module
Summary of knowledge points about Python unpacking
Python learning-variable types
7 features of Python3.9
02. Python data types
Python basic summary
Detailed explanation of data types based on Python
Python exception handling
A brief summary of the difference between Python2 and Python3
Python3 built-in module usage
Python processing json summary
Python built-in function -compile()
Python interview questions summary
Basics of Python syntax
Python3 built-in function table.md
Python basic data types
Python advanced usage summary
Basic syntax of Python
Basic knowledge of Python (1)
Prettytable module of python
Python basic data types
09. Common modules of Python3
Summary of ubuntu usage