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
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.

🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.7 documentation
The try … except statement has an optional else clause, which, when present, must follow all except clauses. It is useful for code that must be executed if the try clause does not raise an exception.
Discussions

try except else
Sign up · Log in · Reset your password · Create account · Reset password · Create a new account More on forum.nim-lang.org
🌐 forum.nim-lang.org
Why do we use try/except?

so what is the different here?

If you don't catch it, the program halts. If you use a try / except block, then you can program in what to do if the input is invalid. A normal choice would be to prompt the user that the input was invalid and try again.

Furthermore, it seems like all the try/except examples could be replicated with an if statements.

Yes at this point. But that won't always be the case. For example, you can't have an if statement that will tell if a http connection will work. Also, an if / else block does not gain you anything; it's just as long or longer as a try / except block, and slightly slower.

More important however is python's "duck typing" philosophy. In python, we don't waste time with tests; we blindly forge ahead and have the except block as a backup plan. In other words, if you expect a duck, and the object you get quacks, that's good enough. No need to test if it actually is a duck.

See python's definition's of duck-typing, EAFP and LBYL.

More on reddit.com
🌐 r/learnpython
13
33
August 17, 2017
I'm new to Try and Except clauses. I don't understand why this code doesn't work.
Three comments: You can format code blocks in Reddit (if you are on Fancy Pants editor, click the three dots, and it will show you). Especially in Python, indentation and formatting are important, so please use it in the future. This code is working for me. I don't know what the issue is. Your error message is from an online tutoring thing, so it's not actually useful. Check that your indentations are all consistent. It is also possible that there is an error in the hidden test code like they say. Don't use bare except like this. In this case, what you are guarding against is an IndexError where your index (4) is larger than the size of the string. So instead do: food = ["chocolate", "chicken", "corn", "sandwich", "soup", "potatoes", "beef", "lox", "lemonade"] fifth = [] for x in food: try: fifth.append(x[4]) except IndexError: pass print(fifth) (this is the code block I mentioned) Maybe try this code catching the specific exception. Perhaps that is what they were testing for. More on reddit.com
🌐 r/learnpython
19
1
June 21, 2021
Try and Except... Is there a way to make except loop back to a specific point.
You need to put the while clause where you want the loop to go back to. That is, the while clause should probably be somewhere before the try. while True: # get input from user # try to convert it to a number # except when there's a problem # show an error message # restart the loop # else stop the loop More on reddit.com
🌐 r/learnpython
11
3
May 22, 2014
🌐
Reddit
reddit.com › r/python › try except else question- when do you use else?
r/Python on Reddit: Try Except Else question- when do you use Else?
October 15, 2022 -

My understanding is that Else runs if Try succeeds without any exceptions. What are the uses for this where you couldn’t just put that code in the Try statement?

🌐
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 NameError: print("Variable x is not defined") except: print("Something else went wrong") Try it Yourself » · See more Error types in our Python Built-in Exceptions Reference.
🌐
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
Find elsewhere
🌐
Real Python
realpython.com › python-exceptions
Python Exceptions: An Introduction – Real Python
March 18, 2026 - except allows you to catch and handle the exception or exceptions that Python encountered in the try clause. else lets you code sections that should run only when Python encounters no exceptions in the try clause.
🌐
Facebook
facebook.com › groups › pythontw › posts › 10156515405538438
Learn the best use cases of try/except/else/finally in python ...
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter10.03-Try-Except.html
Try/Except — Python Numerical Methods
EXAMPLE: Capture the exception. x = '6' try: if x > 3: print('X is larger than 3') except TypeError: print("Oops! x was not a valid number.
🌐
Quora
quora.com › What-are-try-except-else-finally-in-python
What are try except else finally in python? - Quora
Answer (1 of 2): In Python, [code ]try[/code], [code ]except[/code], [code ]else[/code], and [code ]finally[/code] are keywords used for handling exceptions and implementing exception handling logic: 1. [code ]try[/code] and [code ]except[/code]: * [code ]try[/code] block: It encloses the code...
🌐
Medium
medium.com › @luqmanilman › what-is-the-difference-between-a-try-except-statement-and-an-if-else-statement-in-the-python-92bd4e978dcc
“What is the difference between a ‘try-except’ statement and an ‘if-else’ statement in the Python language?” | by Luqman Ilman Muhammad | Medium
June 7, 2024 - The “try-except” statement in Python allows you to handle exceptions (errors) gracefully. It permits you to specify a block of code that may raise an exception and then define how to handle that exception if it occurs.
🌐
Plain English
python.plainenglish.io › still-confused-about-try-except-else-and-finally-this-guide-clears-it-up-024af2292587
Still Confused About Try, Except, Else, and Finally? This Guide Clears It Up! | Python in Plain English
March 17, 2025 - Exception handling is a crucial aspect of programming that ensures the smooth execution of a program even when unexpected errors occur. Python provides a robust exception-handling mechanism that…
🌐
YouTube
youtube.com › watch
Python Error Handling Part 3 | Try-Except-Else, Finally & Nested Try-Except Explained - YouTube
🚀 Python Error Handling Part 3 – Try-Except-Else, Finally & Nested Try-ExceptIn this video, we continue our journey into error handling in Python. You’ll le...
Published: August 26, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › python › errors-and-exceptions-in-python
Errors and Exceptions in Python - GeeksforGeeks
May 29, 2026 - Errors are problems in a program that causes the program to stop its execution. On the other hand, exceptions are raised when some internal events change the program's normal flow. A syntax error occurs when the code does not follow Python’s writing rules.
🌐
Medium
medium.com › @radityafasya45 › try-except-vs-if-else-in-python-whats-the-difference-a3df90770cb2
Try-Except vs. If-Else in Python: What’s the Difference? | by Radithya Zuhayr Fasya | Medium
February 24, 2025 - Try-Except is ideal for scenarios where errors like division by zero, file not found, or invalid input might occur. On the other hand, If-Else is best for predictable conditions such as checking user inputs or creating decision trees.
🌐
Quora
quora.com › What-are-the-functions-and-exact-uses-of-the-try-except-else-and-finally-clauses-in-Python-3
What are the functions and exact uses of the try, except, else, and finally clauses in Python 3? - Quora
Answer (1 of 3): To make core more safe. Without using except, a program throwing an error will print a traceback to the console. However, the traceback is not very usefull to users, and may not even be visible in graphical applications, thus you can catch an error and display a dialogue box, se...
🌐
APXML
apxml.com › courses › python-for-beginners › chapter-9-handling-errors-exceptions › python-try-except-else
Python `else` Block in try/except | Code on Success
Avoiding Unintended Catches: Place the success-dependent code directly at the end of the try block. If that code (the success code) itself raises an exception that matches one of your except clauses, it would be caught, which might not be what you intended. The else block avoids this problem because it's outside the scope directly monitored by the except clauses for the initial try operations.
🌐
Nim Forum
forum.nim-lang.org › t › 9034
try except else
Sign up · Log in · Reset your password · Create account · Reset password · Create a new account
🌐
GeeksforGeeks
geeksforgeeks.org › python › try-except-vs-if-in-python
try-except vs If in Python - GeeksforGeeks
August 13, 2021 - It was mainly developed for emphasis ... in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more efficiently. Most of the people don’t know that Try-Except block can replace if-else (conditional Statements...
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
In Python, all exceptions must be instances of a class that derives from BaseException. In a try statement with an except clause that mentions a particular class, that clause also handles any excep...