Reputation: 159
for line in sys.stdin:
line = line.strip()
uid, profile = line.split('\t')
try:
process(profile)
except:
# do nothing and skip this profile
I would like to skip all profiles that throw exceptions. But python gives me
IndentationError: expected an indented block
at the line "# do nothing and skip this profile".
How do I tell python to do nothing?
Upvotes: 3
Views: 138
Reputation:
Use the pass
keyword:
except:
pass
pass
is basically a do-nothing placeholder.
Also, it is generally considered a bad practice to have a bare except
like that. As explained here, it will catch all exceptions, even those that are unrelated.
Instead, you should catch a specific exception:
except Exception:
Upvotes: 3
Reputation: 54183
The Python "NOP" is pass
...
except:
pass
That said, never use bare except
clauses. They catch things like a KeyboardInterrupt
that you (almost) absolutely NEVER want to handle yourself. If there's nothing SPECIFIC you're catching, do except Exception
Upvotes: 4