Avoid “exception ignored” in python enhanced generator
I have a coroutine (Enhanced generators) in python with some code to be executed after the end of data: def mycoroutine(): try: while True: data = (yield) print data finally: raise ValueError print "END" co = mycoroutine() co.next() for i in (1,2,3): co.send(i) The ValueError exception is not raised but the interpreter simply prints: Exception ValueError: ValueError() in <generator object mycoroutine at 0x2b59dfa23d20> ignored Is there a way to catch the exception in the caller? The exception is raised. The finally block is executed when the generator is closed. Closing a generator is done by