Python provides two very important features to handle the exceptions and errors that Python programs run in. You can use this feature to debug a python program.
Let's see what the exceptions are:
Python Standard exception
| Exception name |
Description |
| Baseexception |
base class for all exceptions |
| Systemexit |
Interpreter Request exited |
| Keyboardinterrupt |
User interrupt execution (usually input ^c) |
| Exception |
base class for general errors |
| Stopiteration |
There are no more values for iterators |
| Generatorexit |
Generator (generator) exception occurred to notify exit |
| StandardError |
Base class for all built-in standard exceptions |
| Arithmeticerror |
base class for all numeric calculation errors |
| Floatingpointerror |
Floating-point calculation error |
| Overflowerror |
Numeric operation exceeds maximum limit |
| Zerodivisionerror |
Except (or modulo) 0 (all data types) |
| Assertionerror |
Assertion statement failed |
| Attributeerror |
Object does not have this property |
| Eoferror |
No built-in input, EOF Mark reached |
| EnvironmentError |
Base class for operating system errors |
| IOError |
Input/output operation failed |
| OSError |
Operating system error |
| Windowserror |
System call failed |
| Importerror |
Failed to import module/object |
| Lookuperror |
base class for invalid data queries |
| Indexerror |
This index is not in the sequence (index) |
| Keyerror |
This key is not in the map |
| Memoryerror |
Memory overflow error (not fatal for Python interpreter) |
| Nameerror |
Object not declared/initialized (no attributes) |
| Unboundlocalerror |
To access uninitialized local variables |
| Referenceerror |
Weak references (Weak reference) attempt to access objects that have been garbage collected |
| RuntimeError |
General run-time errors |
| Notimplementederror |
Methods that have not been implemented |
| SyntaxError |
Python syntax error |
| Indentationerror |
Indentation Error |
| Taberror |
Tab and Space Mix |
| Systemerror |
General Interpreter system error |
| TypeError |
An operation that is not valid for type |
| ValueError |
Invalid parameter passed in |
| Unicodeerror |
Unicode-related errors |
| Unicodedecodeerror |
Error in Unicode decoding |
| Unicodeencodeerror |
Unicode encoding Error |
| Unicodetranslateerror |
Unicode Conversion Error |
| Warning |
Base class for warnings |
| Deprecationwarning |
Warnings about deprecated features |
| Futurewarning |
Warning about the change in the construction of future semantics |
| Overflowwarning |
Old warning about auto-promotion to Long integer |
| Pendingdeprecationwarning |
Warnings about attributes that will be discarded |
| Runtimewarning |
Warning for suspicious run-time behavior (runtime behavior) |
| Syntaxwarning |
Warning of suspicious syntax |
| Userwarning |
Warnings generated by user code |
What is an exception?
An exception is an event that occurs during program execution and affects the normal execution of the program.
In general, an exception occurs when Python does not handle the program properly.
The exception is a Python object that represents an error.
When a Python script exception occurs, we need to capture and process it, or the program terminates execution.
Python Dafa Throw exception