Mark Wooding wrote:
> 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.

        This is an interesting setup, but I'm not sure I see why you need 
it.  If you know that, in a particular context, you want toy(x, 0) to 
result in 42 instead of ZeroDivisionError, why not just define

safeToy(x, y):
        try:
                retVal = toy(x, y)
        except ZeroDivisionError:
                retVal = 42
        return retVal

. . . and then call safeToy instead of toy in those contexts?

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
        --author unknown
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to