How can I ignore all exceptions for a given block of code such that an exception is not only ignored, but also doesn't prevent the next line from being executed?
For example, consider the following code
#!/usr/bin/env python3
def one():
raise Exception
print( 'one' )
def two():
print( 'two' )
try:
one()
two()
except:
pass
I would like the above code to print two
but it actually prints nothing because the "ignored" exception still prevents the execution of two()
.
Is it possible to actually ignore exceptions in blocks of python code?
EDIT: The application for this is for a close()
function that does some cleanup when my app is exiting. It needs to happen as fast as possible and will consist of many commands (not just two as the example I used, but it could be dozens of unrelated actions). And if one line fails, it shouldn't stop the next from trying. Please tell me there's a better option than "just use more than one try
block"..