ConFoo Montreal 2017 Calling for Papers


(PHP 5 >= 5.5.0)

Generator::throwThrow an exception into the generator


public mixed Generator::throw ( Exception $exception )

Throws an exception into the generator and resumes execution of the generator. The behavior will be the same as if the current yield expression was replaced with a throw $exception statement.

If the generator is already closed when this method is invoked, the exception will be thrown in the caller's context instead.

Elenco dei parametri


Exception to throw into the generator.


Example #1 Throwing an exception into a generator

function gen() {
    try {
    } catch (
Exception $e) {
"Exception: {$e->getMessage()}\n";
$gen gen();
$gen->throw(new Exception('Test'));

Il precedente esempio visualizzerĂ :

Exception: Test

Valori restituiti

Returns the yielded value.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top