When we deal with exception handling and in the try block, the statements in the else block are executed if execution falls off the bottom of the try - if there was no exception.
So, following are some important note that will be useful at the time of dealing with Exceptions Handling:-
It is better to use the else clause than adding additional code to the try clause because it avoids accidentally catching an exception that wasn’t raised by the code being protected by the try ... except statement.
For example, you want to catch exceptions that is raised by throwing an IOError exception, but there's something else you want to do if the first operation succeeds, and you don't want to catch an IOError from that operation, you might write something like this:
# we don't want to catch the IOError if it's raised another_operation_that_can_throw_ioerror()
If you just need to put another_operation_that_can_throw_ioerror() after operation_that_can_throw_ioerror, the except would catch the second call's errors. And if you put it after the whole try block, it'll always run, and not until after the finally.
The else lets you make sure:-
The second operation will run only if there's no exception.
The second operation will always run before the finally block.
If any IOErrors raised by the second operation then they aren't caught here.