Jochem Maas wrote:
here is a list of built in Exception classes, I'd figured I'd start using them,
and save on rolling my own:

Exception
ErrorException
DOMException
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
RuntimeException
OutOfBoundsException
OverflowException
RangeException
UnderflowException
UnexpectedValueException
PDOException
SQLiteException
ReflectionException
mysqli_sql_exception
PharException

for starters, what is meant by DomainException? and ErrorException?

secondly if you wanted to throw an exception for a missing config file in
your app, which would you choose? if you ask me only Exception is really
correct in this instance, but it's not very descriptive is it.

the last five in the list are only handy if you use those extensions, and
then only in terms of catching.

anyone actually using these built-ins in their work?


I've been using the php5 exception try/catch feature for several months and 
find it most useful. e.g.,

try
    {
        $flagsArray = getHideAndMarkFlagsFromPost(); //Get the records flagged 
mark and hide
        $recordsArray = getRegistryTable();
        $userDataArray = $recordsArray[$flagsArray['marks'][0]];
    }
    catch (Exception $e)
    {
        $errorMsg = $e->getMessage();
    }
In my getHideAndMarkFlagsFromPost() function, I have:

if(empty($flagsArray)) throw new Exception("No records were flagged");

For your missing config file, simply use something like:
if(!file_exists('foo') throw new Exception("Config file missing");
return $file-string; // or whatever.

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

Reply via email to