Python’s Built-In Exceptions
BaseException
The base class for all built-in exceptions.
Exception
All built-in, non-system-exiting exceptions are derived from this class.
All user-defined exceptions should also be derived from this class.
StandardError
The base class for all built-in exceptions except StopIteration, GeneratorExit, KeyboardInterrupt and SystemExit. StandardError itself is derived fromException.
- Python Programming – Python User Defined Exceptions
- Python Programming – Exception Handling
- Python Programming – Exception Handling
ArithmeticError
The base class for those built-in exceptions that are raised for various arithmetic errors: OverflowError, ZeroDivisionError, FloatingPointError
LookupError
The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: IndexError, KeyError.
This can be raised directly by sys.setdefaultencoding()
EnvironmentError
The base class for exceptions that can occur outside the Python system:
IOError, OSError.
AssertionError
Raised when an assert statement fails.
AttributeError
Raised when an attribute reference or assignment fails.
EOFError
Raised when one of the built-in functions (input() or raw_input()) hits an end-of-file condition (EOF) without reading any data.
FloatingPointError
Raised when a floating point operation fails.
GeneratorExit
Raise when a generator’s close() method is called.
It directly inherits from Exception instead of StandardError since it is technically not an error.
Also Read: Python Interview Questions on Data Types and Their in-built Functions