Re: Make try/catch brackets optinal
| From: | Alexey Zakhlestin | Date: | Fri, 20 Jul 2012 09:49:24 +0000 |
| Subject: | Re: Make try/catch brackets optinal | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61552@lists.php.net to get a copy of this message | ||
On 20.07.2012, at 12:33, Ivan Enderlin @ Hoa wrote:
> Making braces optional for try/catch does:
> + not break backward compatibility;
> + add consistency in the PHP syntax;
> ± offer a new way to write buggy programs but no more than with other control structures
> (think about goto ;-)).
>
> I see more + than - here. Am I wrong?
You are not wrong. This is the inconsistency and it makes sense to fix it.
We are definitely not going to "unfix" it for if/else, so I "+1" your proposal
in advance
> Moreover, in parallel, a new idea has been landing: introducing the “rescue” keyword as a
> shortcut/replacement of try/catch, such as:
> $foo = callThatCouldThrow() rescue 'oof';
> Is it possible to chain it, such as:
> $foo = callThatCouldThrow() rescue anotherCallThatCouldThrow() rescue 'oof?';
>
> Maybe we should start another topic because it could be a nice idea.
I don't see value in this. "finally" would be much more valuable.
try {
doSomething();
} catch (\Exception $e) {
handleException();
} finally {
genericCleanup() // called if everything is good, if everything is bad or even if exception is
rethrown
}
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc