Hacker News new | past | comments | ask | show | jobs | submit login

  ... it is wrong design. Since obviously you are using the exceptions as control flow.
What convoluted understanding of "control flow" makes an exception unworthy of use as control flow?

Exceptions aren't bugs, they're simply exceptional conditions. If you use them right they pose no problem but serve to make the code more legible.




I find it laughable that they’re arguing this from the "don’t abuse exceptions as control flow" angle considering that PHP 5.3 introduced goto.


Oh, great, another way for the rails nazies here at work to make fun of php... -_-U


PHP is like legos or loxblox, mmmkay? And I'm not saying legos aren't awesome, or that you can't build a house out of it. Absolutely you can.


Yeah, I know. But working on a wood statue with a humble knife should not be an excuse for the chainsaw guy to call you a dumb bastard for not be doing the statue with the chainsaw, "like proper men should do". Yes, the quoted phrase was actually heard on my office. Go figure...

( ...and I don't have anything against ruby. I'm learning rails. www.railsforzombies.com is great. In fact, my php is made on cakephp and lithium, which are pretty similar to rails... )


Exceptions are control flow and nothing more. Any try/catch block could be rewritten with if/else checks on various error flags, assuming such flags are exposed. See C. Exceptions are just a clean way to write error handling and stack unwinding code without large amounts of if/else and return statements. Saying "finally" isn't necessary is like saying "foreach" isn't necessary when you have "while".


"Any try/catch block could be rewritten with if/else checks on various error flags"

Well, yes and no. Correctly writing your if flags to be polymorphic on the type of the exceptions is certainly possible but you're getting into the domain of things that a compiler really ought to be doing for you.

I've successfully made use of polymorphic exceptions, but I will freely concede I seem to be in the minority. Also I love having them being objects because then I also load the logic into them for presentation both to the human user and the developer which turns out to be really useful but also apparently a minority idea. Adding that to your if/else blocks would be insane.

Frankly, exceptions are badly underutilized, but one could say that about quite a lot of OO concepts, really. Many people understand the surface forms but manage to miss the point entirely. If that's all you've ever seen for exception handling I can understand why you wouldn't think it's very useful.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: