php-src/Zend/tests/generators/basic_yield_from_exception_handling.phpt
Nikita Popov 3ae995f03c Tweak uncaught exception message display
This implements a reduced variant of #1226 with just the following
change:

-Fatal error: Uncaught exception 'EngineException' with message 'Call to private method foo::bar() from context ''' in %s:%d
+Fatal error: Uncaught EngineException: Call to private method foo::bar() from context '' in %s:%d

The '' wrapper around messages is very weird if the exception
message itself contains ''. Futhermore having the message wrapped
in '' doesn't work for the "and defined" suffix of
TypeExceptions.
2015-05-17 18:47:06 +02:00

60 lines
978 B
PHP

--TEST--
Exceptions in linear yield from setup
--FILE--
<?php
function from($off) {
try {
yield $off + 1;
} catch (Exception $e) { print "catch in from()\n$e\n"; }
yield $off + 2;
}
function gen() {
try {
yield "gen" => 0;
} catch (Exception $e) { print "catch in gen()\n$e\n"; }
try {
yield from from(0);
} catch (Exception $e) { print "catch in gen()\n$e\n"; }
yield from from(2);
}
$i = 0;
try {
for ($gen = gen(); $gen->valid(); $gen->throw(new Exception((string) $i++))) {
var_dump($gen->current());
}
} catch (Exception $e) { print "catch in {main}\n$e\n"; }
var_dump($gen->valid());
?>
--EXPECTF--
int(0)
catch in gen()
Exception: 0 in %s:%d
Stack trace:
#0 {main}
int(1)
catch in from()
Exception: 1 in %s:%d
Stack trace:
#0 {main}
int(2)
catch in gen()
Exception: 2 in %s:%d
Stack trace:
#0 {main}
int(3)
catch in from()
Exception: 3 in %s:%d
Stack trace:
#0 {main}
int(4)
catch in {main}
Exception: 4 in %s:%d
Stack trace:
#0 {main}
bool(false)