On 6/6/06, Steve Bennett stevage@gmail.com wrote:
Assuming this is a general question not specifically related to MediaWiki, the general answer is that exceptions should only be used for exceptional circumstances, and likely failures are better off handled with return codes. It's better to use exceptions for weird things like running out of memory, suddenly being unable to access the disk, or an assertion failing, rather than something as banal as a bad filename being supplied, for instance.
In languages where you have hardware-level access and can detect hardware issues, exceptions make sense. For a language such as PHP where you don't have such low-level access and will not run into such issues, the severity threshold for using an exception is lowered, IMO. Personally, I handle errors in PHP using a custom error handler as follows:
If something wrong happens in a function, you call trigger_error() and pass an error message and severity constant. I override PHP's error handler with set_error_handler(). In my custom error handler function, if the error severity is great enough to warrant program termination, I throw an exception. If not, the error simply gets logged or handled in its own way. Basically, I use exceptions to terminate program execution and return types to alter program execution.
Greg