Exception feature creep! (was: re-entering in the normal flow after an exception is raised)

Lonnie Princehouse finite.automaton at gmail.com
Sat Oct 2 17:16:21 EDT 2004


michele.simionato at gmail.com (Michele Simionato) wrote in message news:<4edc17eb.0410011905.72494b5d at posting.google.com>... 
> 
> Well, actually that is NOT what I asked. Erik Max Francis got my point:
> 

Indeed!  I seem to have completely misinterpreted your post!  

At least it.. raised.. some interesting conjecture about exceptions.  
I wonder if yield could be abused to simulate resumable exceptions
under certain situations?

class ResumableException(Exception): pass

def foo():
  if something_has_gone_wrong():
     yield ResumableException
     print "Resumed!"
  

result = foo()
if result is ResumableException:
  if recovery_is_possible():
    foo()   
  else:
    raise result

Far from ideal, but it is a way of suspending and then resuming
execution.  It does have the unfortunate caveat that the caller needs
to be aware of what's coming, which sort of defeats the point of
exceptions.  A kind of homage to the things people do in languages
that lack exception-handling mechanisms...



More information about the Python-list mailing list