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:[email protected] N
50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca
|
+---------------------------------------------------------------------+
Attachment: [application/pkcs7-signature] S/MIME Kryptografische Unterschrift smime.p7s