Re: Which Exception to use ....
| From: | Al | Date: | Fri, 22 Aug 2008 21:28:02 +0000 |
| Subject: | Re: Which Exception to use .... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278549@lists.php.net to get a copy of this message | ||
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.