Phillip J. Eby wrote: > At 10:00 PM 6/1/2005 +0200, Eric Nieuwland wrote: >> Phillip J. Eby wrote: >> > -1, too confusing. >> >> A matter of taste, I guess. IMHO 'with' secretly handling exceptions >> is >> confusing. > > It doesn't secretly handle them; it simply gets access to them, which > is an entirely different thing. > > By confusing, I mean that it is not clear from your construct what > exceptions are caught by the 'except' clause, due to its structural > layout. It's also not clear whether the __enter__/__exit__ of EXPR > wrap BLOCK1 only, or both BLOCK1 and BLOCK2. These aspects are > "confusing" because whatever decision you make about the semantics, > someone will have to *remember* them, as opposed to being > unambiguously represented by the block structure. > > By contrast, if you remove the except: clause from your construct, it > is clear that BLOCK1 is what is wrapped, and there is no possible > confusion about who sees what exceptions. Exceptions inside the block > are communicated to __exit__, exceptions outside (including those in > the 'with' statement itself) are not.
OK. This forwarding (is that the proper expression here?) of an exception to __exit__ is what I meant by 'secretly handling'. If everybody agrees I'll write with EXPR as VAR: try: BLOCK1 except EXCEPTION: BLOCK2 instead. Seems a waiste to me, though. I was thinking about 'try EXPR [as VAR]:' as a 'try' that handles uncaught exceptions by forwarding it to EXPR's __exit__ method. No confusion with me. --eric _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com