To catch all possible exceptions, catch BaseException
. It's on top of the Exception hierarchy:
Python 3: https://docs.python.org/3.9/library/exceptions.html#exception-hierarchy
Python 2.7: https://docs.python.org/2.7/library/exceptions.html#exception-hierarchy
try:
something()
except BaseException as error:
print('An exception occurred: {}'.format(error))
But as other people mentioned, you would usually not need this, only for specific cases.