Tjerk, I've been hearing this argument from time to time and I don't understand > it; aren't exceptions created with the sole purpose of (error) flow > control? > > If so, then how can "exceptions for flow control" and "very bad idea" be > mentioned in the same sentence unless there are particular bad use cases > that are implicitly referred to when saying this? > > If not, then perhaps my understanding of exceptions needs a spring cleaning > :)
Correct, Exceptions aren't supposed to be used for flow control. However, this isn't about flow control. This is about throwing the exception in the proper context. With generators and coroutines, the code that throws the exception may not actually be a child of the code that called it (from the stack's perspective). Therefore, adding Generator::throw() simply allows for throwing the exception in the proper stack frame (the framew that called the original code). For an example of how this would be useful, read this *awesome* post about coroutines: http://nikic.github.com/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html Anthony