re-entering in the normal flow after an exception is raised

Michele Simionato michele.simionato at gmail.com
Tue Sep 28 18:17:07 CEST 2004


I think I want "re-entrant exceptions" (not sure if this is the
correct name).

Consider the following example:

class NotSeriousException(Exception):
    pass

def do_this():
    raise NotSeriousException()

def do_that():
    pass

def do_this_and_that():
    do_this()
    do_that()

Since the exception is raised at the do_this() level, do_that() will
not be executed. However, since the exception is not that serious, I
would like to catch it and continue from the point the exception was
raised, i.e. something like that:

try:
    do_this_and_that()
except NotSeriousException:
    continue # does not work of course

where "continue" would continue from do_that().

Is there some elegant or hackish way to get this? 
Notice that I do NOT want to modify the source code of
do_this_and_that.
It comes from real life code and I could modify it, but if there was
some
smarter way of getting what I want I would be interested ...

          Michele Simionato



More information about the Python-list mailing list