Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67171 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19985 invoked from network); 26 Apr 2013 16:52:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Apr 2013 16:52:11 -0000 Authentication-Results: pb1.pair.com header.from=amaury.bouchard@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=amaury.bouchard@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.41 as permitted sender) X-PHP-List-Original-Sender: amaury.bouchard@gmail.com X-Host-Fingerprint: 209.85.128.41 mail-qe0-f41.google.com Received: from [209.85.128.41] ([209.85.128.41:58696] helo=mail-qe0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/16-15719-9B0BA715 for ; Fri, 26 Apr 2013 12:52:10 -0400 Received: by mail-qe0-f41.google.com with SMTP id b4so2922526qen.0 for ; Fri, 26 Apr 2013 09:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=rDi6GT0O2NOhPZGPRzEwlFEIA3YBWHMmv6Rffaya4yE=; b=IhNY4f49PuWiz28z04SaxRIZ+l/sChjBDR9aSEpFDjBeXtGYWNSH2tu5UCjaXCVtun uzeux0DuBjcANKh03sMpFskpDdCN35exSKHjZTGf8oTJin6Cv8MttEqh5k0J4HRBwSJk XBVT27E8XI0PZhMUxAfD4WL4/yduoXaWj+JHNj+hpLauVdV7eD9ftD0eXLIaXxqHhGRE dJQZ9Eu1zsJcxy0uDx0FZmspWuPXUioR1peTdBtTXFasFMtKVzmP2Loe3wZpcKMN5FbG xvgtSHOl1v60ljZ588Fyzmj/KlTeexhFdOhRWNJpJzYb/Kb1v57F8yoAzqRpjyIzPc2O oGIw== X-Received: by 10.49.15.161 with SMTP id y1mr19587078qec.3.1366995127110; Fri, 26 Apr 2013 09:52:07 -0700 (PDT) MIME-Version: 1.0 Sender: amaury.bouchard@gmail.com Received: by 10.49.133.39 with HTTP; Fri, 26 Apr 2013 09:51:47 -0700 (PDT) In-Reply-To: <170891005.EmXIrsICLC@rofl> References: <170891005.EmXIrsICLC@rofl> Date: Fri, 26 Apr 2013 18:51:47 +0200 X-Google-Sender-Auth: LXuRTjeElBUtIfQyz1-kr5r73mY Message-ID: To: Patrick Schaaf Cc: PHP Internals , Julien Pauli Content-Type: multipart/alternative; boundary=047d7bdc055cf630e604db465abf Subject: Re: [PHP-DEV] Continued try blocks From: amaury@amaury.net (Amaury Bouchard) --047d7bdc055cf630e604db465abf Content-Type: text/plain; charset=ISO-8859-1 I will answer, as the idea came from Pierrick Charron and I :-) Sometimes, you call functions (or methods) and you know they can throw some exceptions. But you don't want to stop all computations just because one of them raised an exception. Maybe you just want to log it, and go to the next call. If you write that: try { $o->method1(); $o->method2(); $o->method3(); } catch (Exception $e) { add_to_log($e->getMessage()); } If method1() raises an exception, it's not possible to execute method2(). And so it forces us to write ugly code like that: try { $o->method1(); } catch (Exception $e) { add_to_log($e->getMessage()); } try { $o->method2(); } catch (Exception $e) { add_to_log($e->getMessage()); } try { $o->method3(); } catch (Exception $e) { add_to_log($e->getMessage()); } But honestly, nobody uses a try/catch block for every single line of code! Unfortunately, it's sometimes the only solution... What I'm suggesting is to be able to continue the code execution, from to point where an exception was raised. try { $o->method1(); $o->method2(); $o->method3(); } catch (Exception $e) { add_to_log($e->getMessage()); continue; } In this example, if method1() raises an exception, it will be logged, and then method2() will be called. If method2() raises an exception, it will be logged, and then method3() will be called. Is method3() raises an exception, it will be logged, and the execution will continue after the try/catch block. "continue" is the best keyword for that: The meaning is "please, continue the execution of my code" :-) As Julien said, there is a BC break, when a try/catch block is written inside a loop. But I think it's not a major usage, and it's a minor inconvenient. Amaury 2013/4/26 Patrick Schaaf > On Friday 26 April 2013 16:41:17 Julien Pauli wrote: > > > *try {* > > * foo();* > > * bar();* > > * baz();* > > *} catch (SomeException $e) {* > > * dosomestuff();* > > * continue; /* Here is the feature, go back to try block */* > > *} catch (Exception $e) {* > > * dosomething();* > > *}* > >... > > So, in this example, if, say, bar() throws a SomeException , the code > > would then resume and execute baz() after the catch block. > > What exactly would it "continue" with? > > The next instruction after whereever the "throw" was? > > The toplevel function call (or other code) next after the toplevel > function in > the try block that threw up? > > The first answer won't work because any object live when bar() threw but > only > referenced in the call stack below the try block, will already have been > destructed. > > The second answer appears ... semantically dubious. > > best regards > Patrick > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7bdc055cf630e604db465abf--