Nick Coghlan wrote: > Exception propagation is a different story. What do you want to propagate? > All > exceptions from the body of the for loop? Or just those from the yield > statement? > > Well, isn't factoring out exception processing part of what PEP 343 is for?
> # We can even limit the propagated exceptions to those > # from the outside world and leave the rest alone > def main_generator(): > ... > gen = sub_generator() > for value in gen: > with throw_to(gen): > input = yield value > continue input A point I should have made here (but didn't, despite using it in a later example) is that the "with" versions don't allow the nested generator to suppress the exception. A small refinement to gen.throw() that makes the first argument optional (similar to the raise statement itself) would make it straightforward to allow the generator to suppress passed in exceptions: def main_generator(): ... gen = sub_generator() for value in gen: try: input = yield value except: gen.throw() # Default to sys.exc_info(), just like raise continue input Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ 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