PHP code example of glen / throwable-generator
1. Go to this page and download the library: Download glen/throwable-generator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
glen / throwable-generator example snippets
function generator() {
foreach (range(1, 6) as $x) {
try {
yield $x;
} catch (Throwable $e) {
echo " !! exception: {$e->getMessage()}\n";
}
}
}
$generator = generator();
foreach ($generator as $x) {
echo "process: $x\n";
if ($x % 2 === 0) {
$generator->throw(new RuntimeException($x));
}
}
$generator = new ThrowableGenerator($generator);