Hey internals! I would like to add a ->throw() method to generator objects and as this wasn't part of the proposal that was voted on I'd like to ask back first.
The Generator::throw(Exception $exception) method takes an exception and throws it at the current interruption point in the generator. It basically behaves as if you replaced the current yield statement with a throw statement and resumed the generator. This method is also part of Python's generator implementation (as well as ECMAScript's). I decided not to implement it at first, because I wasn't convinced of its usefulness. But after some further consideration adding it seems to make more sense. Basically the method allows you to do delegate error handling to the coroutine, rather than doing it yourself (as you are not always able to do it). It is particularly useful in more complicated settings, e.g. if you are doing task scheduling through coroutines. For a small sample of how this looks like see http://taskjs.org/. What the ->throw() method would do in these examples is that it allows to check for errors by try/catching the yield statement (rather than going for some odd solution with error callbacks). Here is a patch that would add this functionality: https://github.com/nikic/php-src/commit/b16e29fea6cba576d4176524bf43d6e7d00f45fa Anyone against adding this? Nikita