Carl Banks <pavlovevide...@gmail.com> writes: > On Dec 6, 12:58 pm, m...@distorted.org.uk (Mark Wooding) wrote: > > def toy(x, y): > > r = restart('use-value') > > with r: > > if y == 0: > > error(ZeroDivisionError()) > > r.result = x/y > > return r.result > > > > def example(): > > def zd(exc): > > if not isinstance(exc, ZeroDivisionError): > > return > > r = find_restart('use-value') > > if not r: return > > r.invoke(42) > > print toy(5, 2) > > with handler(zd): > > print toy(1, 0) > > You could do that. > > Or, you could just put your try...finally inside a loop.
[You correct `finally' to `except' in a follow-up.] I think you've missed the point almost entirely. Any code called from within the `with handler' context will (unless overridden) cause a call `toy(x, 0)' to return 42. Even if the `with handler' block calls other functions and so on. Note also that the expression of this is dynamically further from where the error is signalled than the resume point (which is within the same function). You can't do this with `try' ... `except'. Which was, of course, the point. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list