When to use Exceptions vs Error Objects vs just plain false/null
I’m in the process of writing a plugin and I’m trying to gauge when to use different approaches of handling errors.
There are three methods I’m considering:
- Throwing an Exception (custom class)
- Returning an Error Object (extension of WP_Error)
- Just return null/false
Some situations that I’m considering
- Trying to get/set an option stored in the Registry that doesn’t exist
- Passing an invalid value to a method (which should be rare)
- Calling a method that the class’ overloader cannot resolve to
Suggestions? Since writing a WordPress plugin has some special considerations, I’m not sure whether it would be worth asking this on a general PHP board.