Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59324 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56539 invoked from network); 2 Apr 2012 13:02:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2012 13:02:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=ivan.enderlin@hoa-project.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ivan.enderlin@hoa-project.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain hoa-project.net from 87.106.212.190 cause and error) X-PHP-List-Original-Sender: ivan.enderlin@hoa-project.net X-Host-Fingerprint: 87.106.212.190 s15355703.onlinehome-server.info Linux 2.6 Received: from [87.106.212.190] ([87.106.212.190:53936] helo=s15355703.onlinehome-server.info) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/32-43049-A43A97F4 for ; Mon, 02 Apr 2012 09:02:04 -0400 Received: from Hwhost2.local (unknown [194.57.88.180]) by s15355703.onlinehome-server.info (Postfix) with ESMTPA id 3EADEE40A4 for ; Mon, 2 Apr 2012 15:02:00 +0200 (CEST) Message-ID: <4F79A348.1010205@hoa-project.net> Date: Mon, 02 Apr 2012 15:02:00 +0200 Reply-To: ivan.enderlin@hoa-project.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] resume after exception From: ivan.enderlin@hoa-project.net ("Ivan Enderlin @ Hoa") 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 "; like "break ;" or "continue ;", 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/