I, too, believes that omitting the exception variable is great. In addition, anonymous catch blocks will shorten the code of "catch (Exception $e)" so... is just a simpler way of writing - and that's what PHP agenda aiming for, doesn't it? be a friendly and readable language.
Reading try { $foo->bar(); } catch { show404Page(); } For example, is readable, short and not contain any extra variables that we didn't used. On Tue, Jun 25, 2013 at 2:18 PM, Joost Koehoorn <joost.koeho...@gmail.com>wrote: > > Hi all, > > > > I just published an RFC that proposes to add catch-statement without > needing to specify a variable, and support for fully > anonymous catches. > > > > Details can be found at: > > > > https://wiki.php.net/rfc/anonymous_catch > > > > Regards, > > > > Joost Koehoorn > > > > Hi. > I am not sure about complete anonymous catch statement (like try { } catch > { }), but I really like the proposal for omitting the exception variable. > > Because in frameworks like Symfony there are defined and used a lot of > special exception types for each cases. > Here's an example that shows what I mean: > > try { > $foo->authenticate($user); > } catch (BadCredentialsException) { > echo "Bad credentials"; > } catch (InactiveAccount) { > echo "Sorry, your account is not active anymore."; > } catch (CurlErrorOnAuthService) { > echo "Please try again later, the login service is currently > unavailable."; > } catch (Exception) { > echo "bla blubb"; > } > > In such a case you do not need any `$e`variable. Netbeans for example > always highlight's these variables because it is not used anywhere. But I > think it looks a bit cleaner if the variable could be omitted, if it's not > needed ;-) > > Best regards > Christian > This is exactly the reason, yes! > > As stated in the RFC, I think it's best that we consider the two ways > separately. Omitting the variable is a much smaller change (and requires > very little code changes) than having a fully anonymous catch. > > I originally dived into this because of a question of Phil Sturgeon on > twitter, requesting for making the variable optional. I took it one step > further and made the whole thing optional, but surely we can decide to only > make the variable optional, I can see how it's bad programming practice to > have fully anonymous blocks (even though sometimes they may be used). Just > throwing this out here to see what you think about it. > > > > Regards, > > Joost > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >