下面是PHP SPL 异常类中可用异常的列表。
Exception
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
RuntimeException
OutOfBoundsException
OverflowException
RangeException
UnderflowException
UnexpectedValueException
Zend FrameworkZend_Exception
只是 PHP 内置异常的一个包装器,但是大多数主要组件都有一个可调用的异常类。
例如:
public function setId($id)
{
$validator = new My_Validator_Id();
if ($validator->isValid($id)) {
$this->id = $id;
return $this;
} else {
throw new Zend_Validate_Exception("$id is not a valid value for the ID field.");
}
}
或使用 PHP 的内置异常:
public function __get($name)
{
$property = strtolower($name);
if (!property_exists($this, $property)) {
throw new \InvalidArgumentException(
"Getting the property '$property' is not valid for this entity");
}
//truncated...
}
Zend Framework 2 有更具体的exceptions
可用。