On Reddit.com there's a discussion that's started up around when to throw exceptions in your PHP applications. The poster asks:
When and where do you throw exceptions? Is it just on database connections? Is it whenever you run a query? Send an email? I'm just curious what the best situations are to throw exceptions and possibly improve my code.
There's a good number of replies so far, some a bit more vague than others:
- "In exceptional circumstances."
- "You throw an except when you can't sensibly handle what has just happened."
- "Fatals for compile-time errors, Exceptions for run-time errors"
- "I throw an exception any time the function being called is either not capable of continuing or it is not going to return the expected results."
- "Exceptions everywhere is not a good thing."
Check out more suggestions and comments in the full post.