The statements in the else block are executed if execution falls off the bottom of the try - if there was no exception. Honestly, I've never found a need.

However, Handling Exceptions notes:

The use of the else clause is better 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.

So, if you have a method that could, for example, throw an IOError, and you want to catch exceptions it raises, 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:

try:
    operation_that_can_throw_ioerror()
except IOError:
    handle_the_exception_somehow()
else:
    # we don't want to catch the IOError if it's raised
    another_operation_that_can_throw_ioerror()
finally:
    something_we_always_need_to_do()

If you just 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 be run, and not until after the finally. The else lets you make sure

  1. the second operation's only run if there's no exception,
  2. it's run before the finally block, and
  3. any IOErrors it raises aren't caught here
Answer from Blair Conrad on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › what's the point of "finally" in "try except" block?
r/learnpython on Reddit: What's the point of "finally" in "try except" block?
September 22, 2020 -

I understand the concept of try: except: block or try: except: else: but I don't seem to understand purpose of the finally: block.Is there a difference between:

try:
    *try something*
except:
    *catch and handle error
finally:
    *continue rest of the script*

And:

try:
    *try something*
except:
    *catch and handle error

*continue rest of the script without 'finally' block*

I suppose there must be some difference,but I can't find any

🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.7 documentation
Many standard modules define their own exceptions to report errors that may occur in functions they define. The try statement has another optional clause which is intended to define clean-up actions that must be executed under all circumstances. For example: >>> try: ... raise KeyboardInterrupt ... finally: ...
Discussions

exception - What is the intended use of the optional "else" clause of the "try" statement in Python? - Stack Overflow
And if you put it after the whole ... the finally. The else lets you make sure · the second operation's only run if there's no exception, ... Also keep in mind that variables used in the try-block CAN be used in the else-block, so you should alway consider using this variant if you don't expect more exceptions in the else-block 2014-08-06T11:56:20.24Z+00:00 ... There's no such thing as a "try-scoped variable". In Python, variable ... More on stackoverflow.com
🌐 stackoverflow.com
exception - Why do we need the “finally:” clause in Python, if we can just write code after the “try:” block? - Stack Overflow
Compare that with the finally: ... of any exception being raised. ... Save this answer. ... Show activity on this post. Using delphi professionally for some years taught me to safeguard my cleanup routines using finally. Delphi pretty much enforces the use of finally to clean up any resources created before the try block, lest you cause a memory leak. This is also how Java, Python and Ruby ... More on stackoverflow.com
🌐 stackoverflow.com
python - Order of execution in try except finally - Stack Overflow
I never really use finally, so I wanted to test a few things before using it more regularly. I noticed that when running: def f(): try: 1/0 # 1/1 except: print('exce... More on stackoverflow.com
🌐 stackoverflow.com
For ... except ... finally - Ideas - Discussions on Python.org
While using the instruction for on a generator, I wanted to catch an exception coming from the generator, and I didn’t found a better solution to use a verbose try except around the for, and which becomes complicated when several errors can come from both iteration and content codes. More on discuss.python.org
🌐 discuss.python.org
0
January 22, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › try-except-else-and-finally-in-python
Try, Except, else and Finally in Python - GeeksforGeeks
try: # Some Code.... except: # optional block # Handling of exception (if required) else: # execute if no exception finally: # Some code .....(always executed) Let’s first understand how the Python try and except works
Published: July 15, 2025
🌐
W3Schools
w3schools.com › python › python_try_except.asp
Python Try Except
try: print(x) except: print("Something went wrong") finally: print("The 'try except' is finished") Try it Yourself »
Top answer
1 of 16
1156

The statements in the else block are executed if execution falls off the bottom of the try - if there was no exception. Honestly, I've never found a need.

However, Handling Exceptions notes:

The use of the else clause is better 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.

So, if you have a method that could, for example, throw an IOError, and you want to catch exceptions it raises, 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:

try:
    operation_that_can_throw_ioerror()
except IOError:
    handle_the_exception_somehow()
else:
    # we don't want to catch the IOError if it's raised
    another_operation_that_can_throw_ioerror()
finally:
    something_we_always_need_to_do()

If you just 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 be run, and not until after the finally. The else lets you make sure

  1. the second operation's only run if there's no exception,
  2. it's run before the finally block, and
  3. any IOErrors it raises aren't caught here
2 of 16
172

There is one big reason to use else - style and readability. It's generally a good idea to keep code that can cause exceptions near the code that deals with them. For example, compare these:

try:
    from EasyDialogs import AskPassword
    # 20 other lines
    getpass = AskPassword
except ImportError:
    getpass = default_getpass

and

try:
    from EasyDialogs import AskPassword
except ImportError:
    getpass = default_getpass
else:
    # 20 other lines
    getpass = AskPassword

The second one is good when the except can't return early, or re-throw the exception. If possible, I would have written:

try:
    from EasyDialogs import AskPassword
except ImportError:
    getpass = default_getpass
    return False  # or throw Exception('something more descriptive')

# 20 other lines
getpass = AskPassword

Note: Answer copied from recently-posted duplicate here, hence all this "AskPassword" stuff.

🌐
Quora
quora.com › How-does-the-finally-clause-work-in-Pythons-try-except-blocks
How does the finally clause work in Python's try-except blocks? - Quora
Answer: It's a default block of code that executes irrespective of exception. It's generally put after the catch block. It only have some default statements to be executed.
Find elsewhere
🌐
Medium
medium.com › towardsdev › try-except-finally-python-how-to-deal-with-exceptions-2c428e0372c8
Try, Except & Finally (Python)— How To Deal With Exceptions | by Liu Zuo Lin | Towards Dev
August 12, 2022 - Sometimes we want to catch specific exceptions and handle them differently. Here’s how we do it: try: # some risky codeexcept ZeroDivisionError as err: print(err) print("cannot divide by 0")except TypeError as err: print(err) print("type…
🌐
DevTechie
devtechie.com › blog › python-try-except-else-and-try-finally
Python: try … except … else and try … finally
In Python, exception handling allows you to gracefully handle errors or unexpected situations that might occur during program execution. Let's dive a little deeper into exception handling with this article. The article explains usage of else andfinally clauses with the try … except construct.
🌐
Medium
galea.medium.com › pythons-try-except-else-finally-explained-f04d47d57125
Python’s “try except else finally” explained | by Alexander Galea | Medium
October 4, 2020 - Understanding else/finally is simple because there are only two cases. The try statement succeeds -> The except statement is skipped -> The else statement runs -> The finally statement runs
🌐
Real Python
realpython.com › python-exceptions
Python Exceptions: An Introduction – Real Python
March 18, 2026 - That file didn’t exist, but instead of letting the program crash, you caught the FileNotFoundError exception and printed a message to the console. ... Imagine that you always had to implement some sort of action to clean up after executing your code. Python enables you to do so using the finally clause: ... # ... try: linux_interaction() except RuntimeError as error: print(error) else: try: with open("file.log") as file: read_data = file.read() except FileNotFoundError as fnf_error: print(fnf_error) finally: print("Cleaning up, irrespective of any exceptions.")
🌐
Sololearn
sololearn.com › en › Discuss › 1728824 › try-except-and-finally-in-python
Try, except and finally in python | Sololearn: Learn to code for FREE!
In the 'except' block you would normally name specific exception types that you intend to handle, at least if you follow good design principles. If any OTHER type of error occurs (whatever you did not expect), you will probably want your program to fail and exit - if that happens, you can decide how to fix that bug. But in the meantime, in the finally block you would free up system resources, close open files, disconnect from database and so on.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Try, except, else, finally in Python (Exception handling) | note.nkmk.me
August 15, 2023 - try: for i in [-2, -1, 0, 1, 2]: print(1 / i) except ZeroDivisionError as e: print(e) # -0.5 # -1.0 # division by zero ... You can specify the code to execute after the except clause using the else and finally clauses, which will be described later.
🌐
VR Soft Tech
vrsofttech.com › python › python-exception-handling-try-catch-finally
Exception Handling in Python | vrsofttech
Exception handling is the way to handle the runtime errors.In Python, runtime errors can be handle using try and except block. ... try: #Block of code except: #Handle the error else: #Execute if no exception finally: #Execute always executes
🌐
Python.org
discuss.python.org › ideas
For ... except ... finally - Ideas - Discussions on Python.org
January 22, 2024 - While using the instruction for on a generator, I wanted to catch an exception coming from the generator, and I didn’t found a better solution to use a verbose try except around the for, and which becomes complicated whe…
🌐
Medium
codeandcompany.medium.com › exception-handling-in-python-try-except-finally-and-custom-exceptions-590bd4722e4e
Exception Handling in Python: try & except, finally, and custom exceptions | by The Startup CTO | Medium
August 8, 2023 - Python’s try and except statements provide a safety net for your code, allowing you to catch and handle exceptions that might occur during execution.
🌐
GUVI
guvi.in › hub › python › try-except-finally-in-python
try…except…finally in Python
The try…except…finally statement is similar to control flow statements like for loop or while loop and its syntax too is similar. >>> try: >>> # Code that might raise an exception >>> # ... >>> except ExceptionType1: >>> # Code to handle ...
🌐
Lobsters
lobste.rs › s › pgh4ss › so_i_ve_been_thinking_about_static_site
So I've Been Thinking About Static Site Generators | Lobsters
February 23, 2026 - I have only dealt with the first kind. I have briefly looked at the second kind but since I already had my own site generator of the first kind (first in Classic ASP, then in PHP, later Python and finally Common Lisp), the second kind never appealed to me.
🌐
Python.org
discuss.python.org › python help
Jump statement in try except finally block - Python Help - Discussions on Python.org
June 29, 2024 - Hi all, can someone say why this is stuck in a infinite loop? Code while True: print("why is this happening") try: break finally: continue Output why is this happening why is this happening why is this happening ...