I like the idea but would prefer another control structure such as CreateTryCatchBlockForEverySingleLine (should be shorter though) rather than continue. The continue keyword is confusing in my opinion. And I would say it should be for every single statement whereupon a statement is defined by either ; or {} rather then for every single line. Thus the following code:
tryStatements{ $a = foo(); if($a > 1){ $i = bar(); }else{ $i = muu(); } for(;$i<10;$i++){ //.. } }catch(Exception $ex){ log($ex); } Would result in: try{ $a = foo(); } catch(Exception $ex){ log($ex); } try{ if($a > 1){ $i = bar(); }else{ $i = muu(); } } catch(Exception $ex){ log($ex); } try{ for(;$i<10;$i++){ //.. } } catch(Exception $ex){ log($ex); } -----Ursprüngliche Nachricht----- Von: Andreas Heigl [mailto:andr...@heigl.org] Gesendet: Freitag, 26. April 2013 20:15 An: Julien Pauli Cc: PHP Internals Betreff: Re: [PHP-DEV] Continued try blocks Am 26.04.13 16:41, schrieb Julien Pauli: > Hello internals, > > I had an idea recently with a friend, about a feature try-catch blocks > could use. > Let me just write an example, you will quickly understand the idea : > > *<?php* > * > * > *try {* > * foo();* > * bar();* > * baz();* > *} catch (SomeException $e) {* > * dosomestuff();* > * continue; /* Here is the feature, go back to try block */* > *} catch (Exception $e) {* > * dosomething();* > *}* > > > > The continue keyword would resume the execution from where it had > diverged, according to the function which led to the SomeException > catch block. > > So, in this example, if, say, bar() throws a SomeException , the code > would then resume and execute baz() after the catch block. > > Just presenting the idea here, no RFC actually , I'm collecting > thoughts and notices. > > Julien.Pauli > Hi Julien. What about the following example? try { $foo = $bar->getObject(); $foo->doSomething() } catch(Exception $e) { continue // Or whatever shall be used } When $bar->getObject throws an Exception no $foo is set. So the next line will result in a "PHP Fatal error: Call to a member function doSomething() on a non-object". So where shall the "continue" actually continue? In the line after the exception was thrown? In the line following the last line $foo was accessed in? Or would something like CreateTryCatchBlockForEverySingleLine { $bar->doOne(); $bar->doNext(); $bar->doSomethingElse(); } catch(Exception $e) { doSomethingWithTheException($e); } resulting in try { $bar->doOne(); } catch(Exception $e) { doSomethingWithTheException($e); } try { $bar->doNext(); } catch(Exception $e) { doSomethingWithTheException($e); } try { $bar->doSomethingElse(); } catch(Exception $e) { doSomethingWithTheException($e); } be more what you are talking about? Regards Andreas -- ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andr...@heigl.org N 50°22'59.5" E 08°23'58" | | http://andreas.heigl.org http://hei.gl/wiFKy7 | +---------------------------------------------------------------------+ | http://hei.gl/root-ca | +---------------------------------------------------------------------+ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php