Yea I realize that, but the expert opinion of others are often used in this forum so I figured I'd join the party.Weirdan wrote:This is an opinion mostly, even if of an expert. Except performance issues which are (were?) specific to implementation of exceptions in C++. And this opinion was expressed 5 years ago.This is a bad idea, partly because the exception-handling system is significantly less efficient than normal program execution; exceptions are a rare event, so the normal program shouldn’t pay for them. Also, exceptions from anything other than error conditions are quite confusing to the user of your class or function
Although exceptions (I assume) are just plain objects in PHP...there is still more overhead than using a return, no dought. However, it is not even the performance issues I am concerned with...it's the over use of exceptions...maybe not even in throwing but in catching and handling...
When it's suggested they are a form of "alternative conditional syntax"...I don't think that practice is as language centric as the implementation details exceptions in C++ versus PHP. Like Bruce says, if you go into the a situation trying to pound everything with your new hammer, you'll quickly get into trouble...I don't think he was pertaining strictly to performance.
Believe it or not, there are indeed situations where codes make for a more elegant solution. Why else would the PHP exception have a getCode()?
After some reflection, I had a slight change of heart in and accepted a more liberal use of try-catch (I certainly like the idea of a more explicit method of error handling). But I still don't see them as a new alternative to conditionals...that kind of thinking will lead you down the path of most resistance, much like noobs expercience when they go bonkers with inheritence or even worse MI. It's a tool, use it by all means, but when you start suggesting replacement or alternative...I'm not so sure I agree 100%.
IMHO it's best to start small with a defined set of rules and build from that. After all, they are called exceptions and not expectations which is the difference I made explicit so as to make the introduction for scoattayy a little easier. If he starts using them as alternative conditionals...without a reason to justify...that would likely lead to something similar to spaghetti code circa GOTO statements. .
Cheers