Exception - how to ignore it ?
alanmk at hotmail.com
Tue Jun 3 17:00:51 CEST 2003
>>> is it possible for an exception handler
>>> to just e.g. print something and set some
>>> global flags but then to have the script
>>> continue just after the statement which
>>> raised the exception?
vivek kumar wrote:
>> If you know exactly where and which statement is raising exception or
> No, that was the question.
> Say an exception is raised at many places and I don't want
> to change the code.
Then I believe the answer is a definitive NO. The relevant section of the python
language reference is
"Python uses the 'termination' model of error handling: an exception handler can
find out what happened and continue execution at an outer level, but it cannot
repair the cause of the error and retry the failing operation (except by
re-entering the offending piece of code from the top)."
"continuing execution at an outer level" also means that you can't resume to the
statement immediately after the one that caused the exception, i.e.
x = 1/0
except ZeroDivisionError, zde:
print "Got an exception: %s" % str(zde)
So if you're not willing or able to restructure your code, then you're out of
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
More information about the Python-list