The 'except' block is useful to catch an exception that is raised in the try block. When there is an exception in the try block, then only the except block is executed. It is written in various formats.
except Exceptionclass as obj:
except (Exceptionclass1, Exceptionclass2,...):
In previous program we are catching two exceptions using two except blocks. The same can be written using a single except block as:
except (TypeError, ZeroDivisionError): print('Either TypeError or ZeroDivisionError occurred.')
The other way is not writing any exception name in except block. This will catch any type of exception, but the programmer cannot determine specifically which exception has occurred. For example,
except: print('Some exception occurred.')
A Python program to understand the usage of try with finally blocks.