Re: Which Exception to use ....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2008/8/22 Jochem Maas <jochem@xxxxxxxxxxxxx>:

> 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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux