Re: resume after exception
| From: | Ivan Enderlin @ Hoa | Date: | Mon, 02 Apr 2012 13:02:00 +0000 |
| Subject: | Re: resume after exception | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-59324@lists.php.net to get a copy of this message | ||
Hi Rasmus,
On 02/04/12 14:44, Rasmus Schultz wrote:
I was just reading about the new async/await keywords in C# 5.0, and while this has no particular relevance to PHP as such, it got me thinking about this idea... What if you could resume execution after an exception was thrown? Fictive example: function test() { echo "Begin Test!\n"; throw new Interrupt(); echo "Execution resumed!"; } try { test(); } catch (Interrupt $e) { echo "Execution interrupted.\n"; resume; } The output of this would be: Begin Test! Execution interrupted. Execution resumed! This feature seems to be interesting (from my point of view) but has similarities with events (see below).
In other words, Interrupt is a new type of Exception, from which you can recover, using the new resume keyword. Why not "resume <i>"; like "break <i>;" or "continue <i>;", or maybe "resume $exception;" to resume with another exception. It could be also interesting to pass $this to the exception (we catch an exception, we fix some data, we resume the execution).The only thing that is disturbing me is your proposition looks like synchronous events. Indeed, we fire an event, it lives somewhere in the code and then execution is resumed. Nevertheless, I think it could be interesting to have this feature for exceptions. Best regards. -- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://lifc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/