No, you cannot do that. That's just the way Python has its syntax. Once you exit a try-block because of an exception, there is no way back in.

What about a for-loop though?

funcs = do_smth1, do_smth2

for func in funcs:
    try:
        func()
    except Exception:
        pass  # or you could use 'continue'

Note however that it is considered a bad practice to have a bare except. You should catch for a specific exception instead. I captured for Exception because that's as good as I can do without knowing what exceptions the methods might throw.

Answer from user2555451 on Stack Overflow
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › python › python_tryexcept_block.htm
Python - The try-except Block
This provides a way to differentiate between the main code that may raise exceptions and additional code that should only execute under normal conditions. Following is the basic syntax of the else clause in Python − · try: # Code that might raise exceptions risky_code() except SomeExceptionType: # Handle the exception handle_exception() else: # Code that runs if no exceptions occurred no_exceptions_code()
Discussions

Best practices for try/except blocks in Python script.
I am thinking that Approach 2 might be the best approach for my problem. Yep, you nailed it. This is exactly what you should do. More on reddit.com
🌐 r/learnpython
16
6
September 20, 2024
Catch exception and continue try block in Python - Stack Overflow
That's just the way Python has its syntax. Once you exit a try-block because of an exception, there is no way back in. ... funcs = do_smth1, do_smth2 for func in funcs: try: func() except Exception: pass # or you could use 'continue' Note however that it is considered a bad practice to have a bare except. You should catch ... More on stackoverflow.com
🌐 stackoverflow.com
exception - Catch any error in Python - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 4 years ago. Is it possible to catch any error in Python? I don't care what the specific exceptions ... More on stackoverflow.com
🌐 stackoverflow.com
python - How can I write a `try`/`except` block that catches all exceptions? - Stack Overflow
Because in Python 3 print is a function and not a statement. Thus you need to call it with (). e.g print(e.message) 2020-12-24T13:53:08.603Z+00:00 ... If you're attempting to catch ALL exceptions, then put all your code within the "try:" statement, in place of 'print "Performing an action which ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Should I catch multiple exceptions separately or together?
Catch them separately if you need different handling for each error type. Group them together if the handling is the same. Example: `except (FileNotFoundError, PermissionError) as e:` if both errors should log and skip the file. Use separate blocks if FileNotFoundError should create the file while PermissionError should alert an admin. Never use bare `except:` or `except Exception:` unless you re-raise the exception after logging—you'll hide bugs and make debugging impossible.
🌐
inventivehq.com
inventivehq.com › home › blog › automation › python try except: complete error handling guide
Python Try Except: Complete Error Handling Guide
When should I use try/except vs just letting the script crash?
Use try/except for errors you expect and can handle (file not found, network timeout, API rate limit). Let it crash for errors that indicate bugs in your code (TypeError, AttributeError, IndexError). If you're wrapping everything in generic `except Exception:` blocks, you're hiding bugs instead of fixing them. Good practice: catch specific exceptions you know might happen, handle them gracefully, and let unexpected errors crash with full stack traces so you can debug them.
🌐
inventivehq.com
inventivehq.com › home › blog › automation › python try except: complete error handling guide
Python Try Except: Complete Error Handling Guide
How do I write error messages that are actually useful?
Include three things: what you were trying to do, what went wrong, and the actual error. Bad: 'Error occurred'. Good: 'Failed to process customer_data.csv at line 247: FileNotFoundError - No such file or directory'. Add timestamps, include variable values that might help debugging, and make errors searchable (use consistent formatting). For production scripts, log errors to a file with full context instead of just printing them. When something breaks at 3 AM, you need to know exactly what happened without running the script in debug mode.
🌐
inventivehq.com
inventivehq.com › home › blog › automation › python try except: complete error handling guide
Python Try Except: Complete Error Handling Guide
🌐
Python documentation
docs.python.org › 3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.14.3 documentation
Exception can be used as a wildcard that catches (almost) everything. However, it is good practice to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on. The most common pattern for handling Exception is to print or log the exception and then re-raise it (allowing a caller to handle the exception as well): import sys try: f = open('myfile.txt') s = f.readline() i = int(s.strip()) except OSError as err: print("OS error:", err) except ValueError: print("Could not convert data to an integer.") except Exception as err: print(f"Unexpected {err=}, {type(err)=}") raise
🌐
Python Land
python.land › home › language deep dives › python try except: examples and best practices
Python Try Except: Examples And Best Practices • Python Land Tutorial
January 29, 2026 - If you removed the try.. except from the code completely and then try to write to the file in read-only mode, Python will catch the error, force the program to terminate, and show this message: Traceback (most recent call last): File “tryexcept.py”, line 3, in
🌐
Coursera
coursera.org › tutorials › python-exception
How to Catch, Raise, and Print a Python Exception | Coursera
If you don’t specify which exceptions a particular except clause should catch, it will handle each one the same way. You can address this issue in a few ways. For example, you can anticipate the errors that may occur and add corresponding except blocks for each one. ... 1 2 3 4 5 6 7 8 9 10 11 12 a = 5 b = "zero" try: quotient = a / b print(quotient) except ZeroDivisionError: print("You cannot divide by zero") except TypeError: print("You must convert strings to floats or integers before dividing") except NameError: print("A variable you're trying to use does not exist")
🌐
Reddit
reddit.com › r/learnpython › best practices for try/except blocks in python script.
r/learnpython on Reddit: Best practices for try/except blocks in Python script.
September 20, 2024 -

I am writing a python script to interact with an instrument. The instrument comes with a python library that I am using in my script.

I am not sure what might be the best practice for using try/except blocks in Python.

Approach 1:

try:
    some_command_1
except Exception as e:
    logger.exception(e)

try:
    some_command_2
except Exception as e:
    logger.exception(e)
.
.
.
try:
    some_command_n
except Exception as e:
    logger.exception(e)

Approach 2:

def main():
    command_1()
    command_2()
    command_n()

if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        logger.exception(e)

When there is an error that raises to a level of an exception, I don't want my script to just catch the exception and move on to the next step.

The step where this error could have occurred might be critical that it is not necessary to proceed with the execution of the remainder of the script.

I am thinking that Approach 2 might be the best approach for my problem. But is it a good practice to do it this way?

The type of error that raises to the level of exception include: Instrument has a problem that it doesn't want to execute the command, lost communications etc.

Find elsewhere
🌐
Inventive HQ
inventivehq.com › home › blog › automation › python try except: complete error handling guide
Python Try Except: Complete Error Handling Guide
November 6, 2025 - Use try/except for errors you expect and can handle (file not found, network timeout, API rate limit). Let it crash for errors that indicate bugs in your code (TypeError, AttributeError, IndexError).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-try-except
Python Try Except - GeeksforGeeks
July 23, 2025 - Example 3: The other way of writing except statement, is shown below and in this way, it only accepts exceptions that you're meant to catch or you can check which error is occurring. Python · # code def divide(x, y): try: # Floor Division : Gives only Fractional Part as Answer result = x // y print("Yeah !
🌐
freeCodeCamp
freecodecamp.org › news › python-print-exception-how-to-try-except-print-an-error
Python Print Exception – How to Try-Except-Print an Error
March 15, 2023 - You can handle each of the exceptions mentioned in this article with try…except. In fact, you can handle all the exceptions in Python with try…except.
🌐
Honeybadger
honeybadger.io › blog › a-guide-to-exception-handling-in-python
The ultimate guide to Python exception handling - Honeybadger Developer Blog
March 28, 2025 - Within this function, we use the try-except block to catch any ZeroDivisionError that may occur during the execution of the divide coroutine. ... Error: Division by zero! As expected, the division by zero raises a ZeroDivisionError exception, ...
🌐
Programiz
programiz.com › python-programming › exception-handling
Python Exception Handling (With Examples)
To handle the exception, we have put the code, result = numerator/denominator inside the try block. Now when an exception occurs, the rest of the code inside the try block is skipped. The except block catches the exception and statements inside the except block are executed.
🌐
Tutorialspoint
tutorialspoint.com › python › python_exceptions.htm
Python - Exceptions Handling
Note: In order to catch an exception, an "except" clause must refer to the same exception thrown either class object or simple string. For example, to capture above exception, we must write the except clause as follows − · try: Business Logic ...
🌐
Real Python
realpython.com › python-exceptions
Python Exceptions: An Introduction – Real Python
December 1, 2024 - What you didn’t get to see was the type of error that Python raised as a result of the function call. In order to see exactly what went wrong, you’d need to catch the error that the function raised. The following code is an example where you capture the RuntimeError and output that message to your screen: ... # ... try: linux_interaction() except RuntimeError as error: print(error) print("The linux_interaction() function wasn't executed.")
🌐
WsCube Tech
wscubetech.com › resources › python › try-except
Try Except in Python (Try Catch With Examples)
October 1, 2025 - Learn how to use Try Except in Python with examples to handle errors and exceptions efficiently. Improve your code's stability with simple steps.
🌐
Python Basics
pythonbasics.org › home › python basics › try and except in python
Try and Except in Python - pythonbasics.org
If you open the Python interactive shell and type the following statement it will list all built-in exceptions: ... The idea of the try-except clause is to handle exceptions (errors at runtime). The syntax of the try-except block is: ... try: the code with the exception(s) to catch.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-exception-handling
Python Exception Handling - GeeksforGeeks
1 week ago - Let's see syntax: try: # Code except SomeException: # Code else: # Code finally: # Code · try: Runs the risky code that might cause an error. except: Catches and handles the error if one occurs.
🌐
Server Academy
serveracademy.com › blog › python-try-except
Python Try Except - Server Academy
The try and except blocks in Python help you gracefully handle errors, while the else and finally blocks provide more control over your code’s flow. Here’s a quick recap of each component: try: Contains the code that might raise an exception. ...