What is the super-class of Exception in Python? Please provide me the Python exception hierarchy.
Is there any Exception super-class, like Throwable of Java Exception, in Python?
3k Views Asked by Akshay Sharma At
2
There are 2 best solutions below
0
On
You are looking for BaseException.
User defined exception types should subclass Exception.
See the docs.
Exception's base class:Exception hierarchy from the docs confirms that it is a base class for all exceptions:
The syntax to catch all exceptions is:
NOTE: use it very very sparingly e.g., you could use it in a
__del__method during cleanup when the world might be half-destroyed and there is no other alternative.Python 2 allows to raise exceptions that are not derived from
BaseException:It is fixed in Python 3 that enforces the rule: