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 <p...@bof.de> > 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 > >