I'm currently fooling around with an ArrayObject class (I've already passed the woe of PHP having an included-with-core ArrayObject etc.)
Obviously a popular exception for this in Java and other such languages is ArrayIndexOutOfBoundsException.
Now because, as most of us know, PHP does not have such pre-defined exceptions, do you guys create an include page with nothing but the 'generic' excpetion classes or do you all create them as per needed within the same file as the class that throws it? (and have a check to see if it has already been defined?)
As I said.. no brainer, I'm knocking up a Generic Exceptions include file now but was wondering what everyone else does
For those that do not understand my babble..
Generic exceptions:
Code: Select all
<?php
class ArrayIndexOutOfBoundsException extends Exception {}
class StringIndexOutOfBoundsException extends Exception {}
class NullPointerException extends Exception {}
//etc..
?>Code: Select all
<?php
class ArrayIndexOutOfBoundsException extends Exception {}
class MyArrayObject
{
//blah..
/*
*getValue throws ArrayIndexOutOfBoundsException
*/
public function getValue ($ind = null)
{
if (($ind !== null) && (!isset($this->array[(int)$ind])) {
throw new ArrayIndexOutOfBoundsException ('Index ' . strval($ind) . ' is non-existant');
}
}
//blah
}
?>