Re: Which Exception to use ....

From: Date: Sat, 23 Aug 2008 09:52:59 +0000
Subject: Re: Which Exception to use ....
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-278558@lists.php.net to get a copy of this message
2008/8/22 Jochem Maas <jochem@iamjochem.com>: > still leaves the questions as to what a DomainException and a ErrorException > is meant to model. A domain exception is thrown when a value is valid according to its type, but not within the domain of the function that it is being passed to. For example if you had a function that only processed odd numbers, passing it (int)6 would be a domain exception. ErrorExceptions model genuine PHP errors - the mechanism that you manipulate with error_reporting(). You can convert a PHP error to an Exception with set_error_handler(). Your list brings together exceptions from all over PHP which shouldn't really be considered together. For example, many of them are from the SPL. They're supposed to be generic - that's what the SPL is for, it's there to solve a specific class of problems. In that context, those exceptions make complete sense. Other exceptions on your list are only ever meant to be thrown from within PHP itself - they're there for us to catch, not to throw. Take a look at the Zend Framework as an example of best practice in these things. I don't think that throws a single built-in exception (although some of the SPL exceptions might be nice to use, they mostly solve the same class of problems as assert()). -- http://www.otton.org/

« previous php.general (#278558) next »