try:
    doSomething()
except Exception: 
    pass

or

try:
    doSomething()
except: 
    pass

The difference is that the second one will also catch KeyboardInterrupt, SystemExit and stuff like that, which are derived directly from BaseException, not Exception.

See documentation for details:

  • try statement
  • exceptions

However, it is generally bad practice to catch every error - see Why is "except: pass" a bad programming practice?

Answer from vartec on Stack Overflow
Top answer
1 of 12
1242
try:
    doSomething()
except Exception: 
    pass

or

try:
    doSomething()
except: 
    pass

The difference is that the second one will also catch KeyboardInterrupt, SystemExit and stuff like that, which are derived directly from BaseException, not Exception.

See documentation for details:

  • try statement
  • exceptions

However, it is generally bad practice to catch every error - see Why is "except: pass" a bad programming practice?

2 of 12
167

It's generally considered best-practice to only catch the errors you are interested in. In the case of shutil.rmtree it's probably OSError:

>>> shutil.rmtree("/fake/dir")
Traceback (most recent call last):
    [...]
OSError: [Errno 2] No such file or directory: '/fake/dir'

If you want to silently ignore that error, you would do:

try:
    shutil.rmtree(path)
except OSError:
    pass

Why? Say you (somehow) accidently pass the function an integer instead of a string, like:

shutil.rmtree(2)

It will give the error "TypeError: coercing to Unicode: need string or buffer, int found" - you probably don't want to ignore that, which can be difficult to debug.

If you definitely want to ignore all errors, catch Exception rather than a bare except: statement. Again, why?

Not specifying an exception catches every exception, including the SystemExit exception which for example sys.exit() uses:

>>> try:
...     sys.exit(1)
... except:
...     pass
... 
>>>

Compare this to the following, which correctly exits:

>>> try:
...     sys.exit(1)
... except Exception:
...     pass
... 
shell:~$ 

If you want to write ever better behaving code, the OSError exception can represent various errors, but in the example above we only want to ignore Errno 2, so we could be even more specific:

import errno

try:
    shutil.rmtree(path)
except OSError as e:
    if e.errno != errno.ENOENT:
        # ignore "No such file or directory", but re-raise other errors
        raise
🌐
Reddit
reddit.com › r/learnpython › is it okay to use try/finally without except?
r/learnpython on Reddit: Is it okay to use try/finally without except?
February 12, 2016 -

Hi and sorry for the noob question,

I am calling another python script as a subprocess. The python script tries to do X, and if/when it fails it MUST do Y. I had originally been handling this by doing the following:

 try:
    x
except:
   <code to be run>

For what I want to do, would it be better to simply use:

try:
    x
finally:
    y

If I understand correctly, I am basically using except for something finally should be used for at the moment, yes? Is there any downside to not using except for what I want to accomplish?

Top answer
1 of 4
8
Code after finally will be called whether the code after the try works or not. It doesn't care. Gets called every time. If you need something to run IF AND ONLY IF the code in the try FAILS, then you need to use except.
2 of 4
1
try will attempt a piece of code. If that results in exception, you can capture and handle that exception within except. Whether or not an exception occurred, you can run code in a finally block to guarantee that it runs in all circumstances. That way, even if the exception stops the program, code in the finally block will still execute. For your purpose, you may want to have all three in place: try: # try this code which may cause an Exception except AThingHappened as e: # handle the exception finally: # code that occurs whether exception happened or not. When you run code in the except block, it's possible to prevent that exception from stopping your program. This is a good way to handle common errors, such as the one you're expecting when you run your subscript. If you want, you can choose to raise the exception again from inside the except block, which lets it bubble up through the program until something else catches it or the thread ceases execution. In either case, any code in finally will be run. This is useful for some code that might do some clean up, like closing a connection. To more directly answer your question, if you omit the except block, your code in finally will still run, but you won't be handling the exception. Instead, that exception will be raised and you'll see its traceback in the console. If you have some logic you want to use to handle that exception, use an except statement. However, depending on your use-case, you might do better designing something that can work with the with statement . I don't know the specifics of your program, so I can't say if it would be helpful, but it's worth considering before trying to make something that's overly complex using try..except..finally.
Discussions

[SOLVED]How to catch error signals without try / except
Hi, First time posting here. I’d like to catch any error signal produced, be it a NameError, IndentationError, or whatnot. I don’t care to escape them, I would just like to be able to call some simple function whenever such an error occurs. Some people might say that this is a bad idea, ... More on discuss.python.org
🌐 discuss.python.org
6
0
December 19, 2021
Is it okay to use try/finally without except?
Code after finally will be called whether the code after the try works or not. It doesn't care. Gets called every time. If you need something to run IF AND ONLY IF the code in the try FAILS, then you need to use except. More on reddit.com
🌐 r/learnpython
6
11
February 12, 2016
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
Is using try/except bad? How to avoid/substitute it.
try/except is usually used for non-deterministic things. Is the user input OK as floating point? Can you read that file OK? If it's things that are easily deterministic, like reaching the end of a list, then the code would probably cleaner using a different structure. More on reddit.com
🌐 r/learnpython
87
17
February 23, 2024
🌐
Qpython
qpython.com › python-try-without-except-1h9a
Python try Without except – QPython+
January 12, 2026 - How can you structure error handling so that success paths and cleanup run smoothly without catching every exception in the same block? By combining try with else and finally, you can keep error-handling code distinct from normal execution and cleanup logic. The else block runs only when no ...
🌐
Python.org
discuss.python.org › python help
[SOLVED]How to catch error signals without try / except - Python Help - Discussions on Python.org
December 19, 2021 - Hi, First time posting here. I’d like to catch any error signal produced, be it a NameError, IndentationError, or whatnot. I don’t care to escape them, I would just like to be able to call some simple function whenever such an error occurs. Some people might say that this is a bad idea, ...
🌐
W3Schools
w3schools.com › python › python_try_except.asp
Python Try Except
These exceptions can be handled ... an error, the except block will be executed. Without the try block, the program will crash and raise an error:...
🌐
Quora
quora.com › Is-there-an-elegant-way-to-reduce-the-numbers-of-try-except-in-Python-programming
Is there an elegant way to reduce the numbers of try, except in Python programming? - Quora
Answer (1 of 5): Use if conditions. I wouldn’t necessarily say that it’s elegant, but it often boils down to a question of performance. Consider the following scenario, where [code ]x[/code] can take on the value [code ]None[/code]. [code]try: # Do stuff with x except TypeError: # Don't do s...
Find elsewhere
🌐
Eduonix Blog
blog.eduonix.com › home › 2025 › may › error handling in python: master try, except, and best practices
Error Handling in Python: Master Try, Except, and Best Practices - Eduonix Blog
May 13, 2025 - Even experienced developers make mistakes with Python error handling. Here are pitfalls to watch out for: Empty except blocks hide errors, making debugging difficult: # Bad try: result = 10 / 0 except ZeroDivisionError: pass # Silent failure # Good try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero.") Catching Exception or using bare except can mask unexpected errors, complicating debugging. Raising exceptions unnecessarily or without context can confuse users:
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-ignore-an-exception-and-proceed-in-python
How to ignore an exception and proceed in Python?
March 24, 2026 - In some cases, certain exceptions might not significantly affect program execution and can be safely ignored. Python provides several ways to handle this: ... The try/except block allows you to execute code and skip any errors that occur using the pass statement.
🌐
Embedded Inventor
embeddedinventor.com › home › how to properly ignore an exception in try-except in python!
How to properly ignore an exception in try-except in Python!
December 27, 2023 - In today’s article, we will look at how we properly ignore exceptions in Python. As with everything in life, there is a correct way to do things and there are other ways! We will start by seeing the incorrect way of ignoring exceptions and see what is incorrect about them and then proceed to learn about the correct way to ignore exceptions. Without further ado, let’s begin! ... Here we catch whatever exception is raised in the try block using the “except: ” statement.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-try-without-except
Using try without except (ignoring exceptions) in Python | bobbyhadz
The pass statement does nothing and is used when a statement is required syntactically but the program requires no action. In general, using an except statement without explicitly specifying the exception type is considered a bad practice.
🌐
Quora
quora.com › Is-there-any-difference-between-except-and-except-Exception-in-Python
Is there any difference between 'except:' and 'except Exception:' in Python? - Quora
Answer (1 of 2): I had initially misread the question, updated to add some value. Willy Zhang's answer is perfect. Update: Yes, [code py]except:[/code] would handle all exceptions, whereas [code py]except Exception:[/code] would handle only exceptions derived from 'Exception' class, rest of th...
🌐
Python
docs.python.org › 3 › library › asyncio-task.html
Coroutines and tasks — Python 3.14.5 documentation
February 23, 2026 - Return True if the Task is done. A Task is done when the wrapped coroutine either returned a value, raised an exception, or the Task was cancelled.
🌐
Code.org
code.org › en-US › tools › game-lab
Game Lab | Create Games and Animations with JavaScript – No Experience Needed
Create games and animations in Game Lab! A fun, beginner-friendly environment to learn coding with JavaScript and unleash your creativity.
🌐
Playwright
playwright.dev › assertions
Assertions | Playwright
In general, we can expect the opposite to be true by adding a .not to the front of the matchers:
🌐
Medium
galea.medium.com › pythons-try-except-else-finally-explained-f04d47d57125
Python’s “try except else finally” explained | by Alex Galea | Medium
October 4, 2020 - Python’s “try except else finally” explained In Python it’s okay to make assumptions, as long as you’re able to clean up the mess if they turn out to be wrong. In fact, this is not only …
🌐
Note.nkmk.me
note.nkmk.me › home › python
Try, except, else, finally in Python (Exception handling) | note.nkmk.me
August 15, 2023 - Using a wildcard except, you can catch all exceptions, including SystemExit (raised by sys.exit(), etc.) and KeyboardInterrupt (triggered by pressing Ctrl + C). However, it's often preferable not to catch these particular exceptions. In such cases, using Exception instead may be a better option, as described next. You can specify Exception in the except clause, which is the base class for all built-in, non-system-exiting exceptions. Built-in Exceptions - Exception — Python 3.11.3 documentation
🌐
Real Python
realpython.com › python-exceptions
Python Exceptions: An Introduction – Real Python
December 1, 2024 - What does try … except pass do in Python?Show/Hide · Using try … except with pass allows the program to ignore the exception and continue execution without taking any specific action in response to the error.
🌐
Jerry Ng
jerrynsh.com › stop-using-exceptions-like-this-in-python
Stop Using Exceptions Like This in Python
January 19, 2024 - Check out the Python exception hierarchy). Furthermore, it doesn't give us any exceptions objects to inspect. Here’s an example of using bare except, which is not recommended: # Do NOT ever use bare except: try: books = fetch_all_books() send_slack_notification(books) except: # !!! raise · Never ever use bare except block. Note that a bare except is equivalent to except BaseException. Catching every exception could cause our application to fail without ...
🌐
Quora
quora.com › How-do-you-ignore-an-exception-and-proceed-in-python
How to ignore an exception and proceed in python - Quora
Answer (1 of 2): First off, let’s be clear that ignoring exceptions is often not the right thing to do. The classical way to do it is to just accept the exception and pass: [code]>>> def remover(filename): ... import os ... try: ... os.remove(filename) ... except FileNotFoun...