php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71013 Incorrect exception handler with `yield from`
Submitted: 2015-12-02 18:28 UTC Modified: 2015-12-06 01:58 UTC
From: srice at fb dot com Assigned: bwoebi (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0RC8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: srice at fb dot com
New email:
PHP Version: OS:

 

 [2015-12-02 18:28 UTC] srice at fb dot com
Description:
------------
`yield from` seems to sometimes be executing the incorrect catch block when handling exceptions. When the exception is thrown during the execution of the generator, rather than as an explicit `throw()` call, it seems that sometimes catch blocks from calling frames can be skipped.

Test script:
---------------
There are two scripts which exhibit incorrect behavior.

1) https://3v4l.org/KLdee

In this example, notice the catch block in `bar()` is executed, when really the exception happened inside of the `yield from` in the try block, so the catch block in `foo()` should be executed.

2) https://3v4l.org/oMdRC

In this example (which is only different from the previous example by the addition of the `yield 1` in `foo()` and an equivalent `next()` in `bar()`), notice that neither of the exception handlers are called.

Expected result:
----------------
For both 1) and 2)

Starting bar()
Constructing new FooBar
Destructing FooBar
[foo()] Caught Exception
NULL
Unsetting $x
Finishing bar()

Actual result:
--------------
1)

Starting bar()
Constructing new FooBar
Destructing FooBar
[bar()] Caught Exception
Unsetting $x
Finishing bar()

2)

Starting bar()
Constructing new FooBar
Destructing FooBar

Fatal error: Uncaught Exception in /in/oMdRC:6
Stack trace:
#0 [internal function]: FooBar->current()
#1 /in/oMdRC(26): Generator->next()
#2 /in/oMdRC(37): bar()
#3 {main}
  thrown in /in/oMdRC on line 6

Process exited with code 255.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-02 18:35 UTC] nikic@php.net
-Assigned To: +Assigned To: bwoebi
 [2015-12-06 01:54 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=559ede17e109adec5dadff3290090e7141ad40ae
Log: Fixed bug #71013 (Incorrect exception handler with yield from)
 [2015-12-06 01:54 UTC] bwoebi@php.net
-Status: Assigned +Status: Closed
 [2015-12-06 01:56 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=559ede17e109adec5dadff3290090e7141ad40ae
Log: Fixed bug #71013 (Incorrect exception handler with yield from)
 [2015-12-06 01:58 UTC] bwoebi@php.net
Sorry that it took so long, but I was working on something else first ;-)

Nice find though and … fixed!
 [2016-07-20 11:35 UTC] davey@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=559ede17e109adec5dadff3290090e7141ad40ae
Log: Fixed bug #71013 (Incorrect exception handler with yield from)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 05 22:01:28 2024 UTC