What are the types of exceptions in Python exception handling? How many do you know?

In python, different exceptions can be identified by different types (python unifies classes and categories, and types are classes). An exception identifies an error.

1. Common syntax errors

AttributeError Trying to access a property that an object does not have, such as foo.x,however foo No attributes x
 
IOError input/Abnormal output; Basically, you can't open the file
 
ImportError Unable to import module or package; It's basically a path problem or a wrong name
 
IndentationError Syntax error (subclass of); The code is not aligned correctly
 
IndexError The subscript index exceeds the sequence boundary, such as when x There are only three elements, but you try to access them x[5]
 
KeyError An attempt was made to access a key that does not exist in the dictionary
 
KeyboardInterrupt Ctrl+C Pressed
 
NameError Use a variable that has not been assigned to an object
 
SyntaxError Python Illegal code, code cannot be compiled(Personally, I think it's a grammatical mistake (wrong writing)
 
TypeError The incoming object type does not match the required
 
UnboundLocalError An attempt to access a local variable that has not been set is basically due to another
    A global variable with the same name causes you to think you are accessing it
 
ValueError Pass in a value that the caller does not expect, even if the value type is correct

2. More errors

ArithmeticError
AssertionError
AttributeError
BaseException
BufferError
BytesWarning
DeprecationWarning
EnvironmentError
EOFError
Exception
FloatingPointError
FutureWarning
GeneratorExit
ImportError
ImportWarning
IndentationError
IndexError
IOError
KeyboardInterrupt
KeyError
LookupError
MemoryError
NameError
NotImplementedError
OSError
OverflowError
PendingDeprecationWarning
ReferenceError
RuntimeError
RuntimeWarning
StandardError
StopIteration
SyntaxError
SyntaxWarning
SystemError
SystemExit
TabError
TypeError
UnboundLocalError
UnicodeDecodeError
UnicodeEncodeError
UnicodeError
UnicodeTranslateError
UnicodeWarning
UserWarning
ValueError
Warning
ZeroDivisionError

3. All standard exception classes in Python

Exception name describe
BaseException Base class for all exceptions
SystemExit Interpreter requests exit
KeyboardInterrupt User interrupts execution (usually enter ^ C)
Exception Base class for general errors
StopIteration The iterator has no more values
GeneratorExit An exception occurred in the generator to notify it to exit
SystemExit Python interpreter requests exit
StandardError Base class for all built-in standard exceptions
ArithmeticError Base class for all numeric errors
FloatingPointError Floating point calculation error
OverflowError The numeric operation exceeds the maximum limit
ZeroDivisionError Divide (or modulo) zero (all data types)
AssertionError Assertion statement failed
AttributeError Object does not have this property
EOFError No built-in input, EOF flag reached
EnvironmentError Base class for operating system error
IOError Input / output operation failed
OSError Operating system error
WindowsError system call filed
ImportError Failed to import module / object
KeyboardInterrupt User interrupts execution (usually enter ^ C)
LookupError Base class for invalid data query
IndexError This index does not exist in the sequence
KeyError This key is not in the map
MemoryError Memory overflow error (not fatal for Python interpreter)
NameError Object not declared / initialized (no properties)
UnboundLocalError Accessing uninitialized local variables
ReferenceError A weak reference attempts to access an object that has been garbage collected
RuntimeError General runtime error
NotImplementedError Methods not yet implemented
SyntaxError Python syntax error
IndentationError Indent error
TabError Mixing tabs and spaces
SystemError General interpreter system error
TypeError Invalid operation for type
ValueError Invalid parameter passed in
UnicodeError Unicode related errors
UnicodeDecodeError Error in Unicode decoding
UnicodeEncodeError Error encoding Unicode
UnicodeTranslateError Error converting Unicode
Warning Warning base class
DeprecationWarning Warning about deprecated features
FutureWarning Warning about future semantic changes in constructs
OverflowWarning Old warning about automatically promoting to long
PendingDeprecationWarning Warning that features will be discarded
RuntimeWarning Warning of suspicious runtime behavior
SyntaxWarning Warning of suspicious syntax
UserWarning Warnings generated by user code

Remember?

At the end, I recommend a very good learning tutorial for you. I hope it will be helpful for you to learn Python!

Python basics tutorial recommendation : click the blue text on the left to see it!
Python crawler case tutorial recommendation : click the blue text on the left to see it!

Tags: Python

Posted on Fri, 26 Nov 2021 03:31:55 -0500 by Paavero