This was a simple problem I was having earlier. Essentially, solutions like this and this to "ignoring" an exception really don't. Even if they don't crash python anymore, they still stop whatever code was in the initial try clause.
try:
assert False
print "hello"
except AssertionError:
pass
This code will not print "hello", but rather skip over it, going to the pass. My question is, is there an easy way to truly ignore this in Python 2.7? I read about some things going on in 3.4 to make this easier, but I'd rather stay with python 2.7.
I don't think you can, and I don't think you should.
Errors should never pass silently.
Unless explicitly silenced.Zen of Python
It means that it's your duty as a programmer to think where and why exceptions might arise. You should (have to, actually) avoid the temptation to put a long block of code in a try
statement and then think about exceptions. The correct thought flow is:
assert False
assert False
in a try...except...
blockprint 'Hello'
So your code should look like this (other answers are pretty nice, too):
try:
assert False
except AssertionError:
pass
print 'Hello'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With