It is generally a bad practice to suppress errors or exceptions without handling them, but this can be easily done like this:

try:
    # block raising an exception
except:
    pass # doing nothing on exception

This can obviously be used in any other control statement, such as a loop:

for i in xrange(0,960):
    try:
        ... run your code
    except:
        pass
Answer from Oleg Sklyar on Stack Overflow
Discussions

exception - How to continue python script loop even though IOError? - Stack Overflow
I have a program which request info from the twitter API, and from time to time I get an error: IOError: [Errno socket error] [Errno 54] Connection reset by peer I want to know how can I keep my ... More on stackoverflow.com
🌐 stackoverflow.com
January 18, 2012
python - How to bypass errors in arcpy for/while loop? - Geographic Information Systems Stack Exchange
I have a handy script tool that loops through a workspace and renames and copies shapefiles to a feature dataset. However, if there is a corrupted shapefile somewhere in the workspace the script f... More on gis.stackexchange.com
🌐 gis.stackexchange.com
python - Ignore exceptions in a loop - Stack Overflow
I am writing a python program where I need to count the number of errors that come up in the loop. every time an error is returned I add +1 to count and keep running until the program doesn't retur... More on stackoverflow.com
🌐 stackoverflow.com
Python: How to ignore an exception and proceed? - Stack Overflow
I have a try...except block in my code and When an exception is throw. I really just want to continue with the code because in that case, everything is still able to run just fine. The problem is i... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Readthedocs
bandit.readthedocs.io › en › latest › plugins › b112_try_except_continue.html
B112: try_except_continue — Bandit documentation
Errors in Python code bases are typically communicated using Exceptions. An exception object is ‘raised’ in the event of an error and can be ‘caught’ at a later point in the program, typically some error handling or logging action will then be performed. However, it is possible to catch an exception and silently ignore it while in a loop...
🌐
Quora
quora.com › How-do-you-skip-an-error-and-continue-to-run-for-a-loop-and-then-continue-to-the-next-line-Python-development
How to skip an error and continue to run for a loop and then continue to the next line (Python, development) - Quora
Answer (1 of 4): Depends on the severity of the “error”. If something’s raising an Exception, that’s what try/except is all about. Start here: https://realpython.com/python-exceptions/
🌐
DevGenius
blog.devgenius.io › python-how-can-i-skip-an-iteration-in-a-for-loop-if-it-has-an-error-eb072c3aaa84
Python | how can I skip an iteration in a for loop if it has an error | by Moamen Elabd | Dev Genius
May 17, 2023 - Easiest way to solve this issue is to create a try | except lines in the for loop itself, so when the For loop will run it will try the code there but if has an error, instead of breaking the loop you can try another code or Just pass the iteration
Top answer
1 of 2
16

Try Googling for "python on error resume next" or similar. This returns a number of hits including this one from StackOverflow:

If you know which statements might fail, and how they might fail, then you can use exception handling to specifically clean up the problems which might occur with a particular block of statements before moving on to the next section.

1) An option may be to put a try...except block around the line you suspect will cause the problem, namely the CopyFeatures tool.

2) See also the Python reference on errors, specifically section 8.3. Once you have a reference to "e" you may be able to determine its exception type and handle it as required.

Eg this StackOverflow question contains a similar workflow to yours:

for getter in (get_random_foo, get_random_bar):
    try:
        return getter()
    except IndexError:
        continue  # Ignore the exception and try the next type.

raise IndexError, "No foos, no bars"

In your case, in place of "IndexError" you'd use whatever you determined the exception type to be for a corrupt shapefile

2 of 2
7

As Stephen already said you can enclose the CopyFeatures Tool in another try...except Block.

If the tool fails with a specific Shapefile you can log the Tool Message somewhere (I always print it on STDOUT and pipe the outputs to a logfile when i run the script).

What I have to add is: In the Except Block beside the Exception you also have to print the error messages the Tool itself produced. You dont get access to the Tool messages by the Exception (as it should be for sure) but from the arcpy Object by calling

arcpy.getmessages(messageCount - 1)

See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000000m000000 how to call it and how to get the last messages which are possibly related to the specific Shapefile Error.

After logging this you simply let the script continue with the other shapefiles

🌐
TutorialsPoint
tutorialspoint.com › How-to-ignore-an-exception-and-proceed-in-Python
How to ignore an exception and proceed in Python?
May 14, 2025 - import contextlib number = 16 with ... need fine-grained control over exception handling. Use suppress() for cleaner code when you want to ignore exceptions in entire blocks....
Find elsewhere
🌐
Towards Data Science
towardsdatascience.com › home › latest › quick python tip: suppress known exception without try except
Quick Python Tip: Suppress Known Exception Without Try Except | Towards Data Science
January 21, 2025 - Instead, the Python built-in library contextlib provides a function called suppress to handle this more elegantly. ... Suppose we have a list of numbers that may contain zeros in them.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-ignore-an-exception-and-proceed-in-python
How to Ignore an Exception and Proceed in Python - GeeksforGeeks
April 28, 2025 - With the help of the return statement and the break keyword, we can control the flow of the loop.Using return keywordThis statement immediately terminates a function and optionally returns a value.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-break-continue-and-pass-statements-when-working-with-loops-in-python-3
How To Use break, continue, and pass Statements in Python | DigitalOcean
3 weeks ago - Using the else clause helps encapsulate the logic entirely within the loop construct, leading to simpler and more focused code, particularly in short searches or conditional iteration. Suppose you are reading a file line by line and want to check whether it contains a specific keyword. Using a for-else structure allows you to handle both outcomes cleanly: with open("example.txt") as f: for line in f: if "error" in line: print("Error found in file.") break else: print("No errors detected.")
🌐
Stack Overflow
stackoverflow.com › questions › 48615411 › ignore-exceptions-in-a-loop
python - Ignore exceptions in a loop - Stack Overflow
Your count should probably be initialized as 0. If you start with count = 1 you are saying there has already been an error. So if you succeed on the first iteration it'll return x, y, 1 even if you had no errors.
🌐
LearnDataSci
learndatasci.com › solutions › python-continue
Python Continue - Controlling for and while Loops – LearnDataSci
Adding continue here means Python will skip any negative numbers, preventing us from getting a value error. The diagram below shows the process followed inside of our for loop:
🌐
Python
mail.python.org › pipermail › tutor › 2005-July › 040116.html
[Tutor] try except continue
September 14, 2013 - If you really want to ignore the error and move to the next line you have to do a try:except on every line (or function call) try: f() except: pass try: g() except: pass Or put the functions in a list if their parameter lists are null or identical: funcs = [f,g] for func in funcs: try: func() ...
🌐
Python
docs.python.org › 3.3 › tutorial › errors.html
8. Errors and Exceptions — Python 3.3.7 documentation
February 22, 2021 - File name and line number are printed so you know where to look in case the input came from a script. Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs.
🌐
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...
🌐
TutorialsPoint
tutorialspoint.com › How-do-you-properly-ignore-Exceptions-in-Python
How do you properly ignore Exceptions in Python?
September 27, 2019 - This can be done by following codes try: x,y =7,0 z = x/y except: pass OR try: x,y =7,0 z = x/y except Exception: pass These codes bypass the exceptio
🌐
Delft Stack
delftstack.com › home › howto › python › python ignore error
How to Ignore an Exception in Python | Delft Stack
February 2, 2024 - When the pass statement is used in the try...except statements, it simply passes any errors and does not alter the flow of the Python program. The following code uses the pass statement in the except block to ignore an exception and proceed with the code in Python.