summaryrefslogtreecommitdiff
path: root/Zend/tests/generators/generator_throwing_exception.phpt
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-05-30 16:28:33 +0200
committerNikita Popov <nikic@php.net>2012-05-30 16:28:33 +0200
commit0033a525213e68e6ae74b3c3d75fd6ea4beea5d6 (patch)
tree0cd23415795f838fb122e02bb5e941ef4f408d7b /Zend/tests/generators/generator_throwing_exception.phpt
parent879016023566ce162be1d81e973bde9db76dd519 (diff)
downloadphp-git-0033a525213e68e6ae74b3c3d75fd6ea4beea5d6.tar.gz
Allow throwing exceptions from generators
The missing piece is how one can find the next stack frame, which is required for dtor'ing arguments pushed to the stack. As the generator execute_data does not live on the stack one can't use it to figure out the start of the next stack frame. So there must be some other method.
Diffstat (limited to 'Zend/tests/generators/generator_throwing_exception.phpt')
-rw-r--r--Zend/tests/generators/generator_throwing_exception.phpt28
1 files changed, 28 insertions, 0 deletions
diff --git a/Zend/tests/generators/generator_throwing_exception.phpt b/Zend/tests/generators/generator_throwing_exception.phpt
new file mode 100644
index 0000000000..5df4a81132
--- /dev/null
+++ b/Zend/tests/generators/generator_throwing_exception.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Generators can throw exceptions
+--FILE--
+<?php
+
+function *gen() {
+ yield 'foo';
+ throw new Exception('test');
+ yield 'bar';
+}
+
+$gen = gen();
+
+var_dump($gen->current());
+
+try {
+ $gen->next();
+} catch (Exception $e) {
+ echo 'Caught exception with message "', $e->getMessage(), '"', "\n";
+}
+
+var_dump($gen->current());
+
+?>
+--EXPECT--
+string(3) "foo"
+Caught exception with message "test"
+NULL