异常
在线手册:中文 英文
PHP手册

The DomainException class

(PHP 5 >= 5.1.0)

简介

Exception thrown if a value does not adhere to a defined valid data domain.

类摘要

DomainException extends LogicException {
/* 继承的方法 */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public int Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}

异常
在线手册:中文 英文
PHP手册
PHP手册 - N: The DomainException class

用户评论:

mateusz dot charytoniuk at gmail dot com (20-Oct-2011 08:45)

<?php
function renderImage($imageResource, $imageType)
{
  switch (
$imageType) {
  case
'jpg':
  case
'jpeg':
   
header('Content-type: image/jpeg');
   
imagejpeg($imageResource);
    break;
  case
'png':
   
header('Content-type: image/png');
   
imagepng($imageResource);
    break;
  default:
    throw new
DomainException('Unknown image type: ' . $imageType);
    break;
  }
 
imagedestroy($imageResource);
}
?>

johnny dot bojowkarz at gmail dot com (19-Jul-2011 11:27)

<?php
function divide($dividend, $divisor)
{
  if(
$divisor == 0) {
    throw new \
DomainException(
     
'Zero does not belong to the domain of this functions.'
   
);
  }
  return
$dividend / $divisor;
}
?>

<?php
function logarithm($argument, $base)
{
  if(
$base <= 0 || $base == 1) {
    throw new \
DomainException(
     
'Specified base does not belong to the domain of this function.'
   
);
  }
  if(
$argument <= 0) {
    throw new \
DomainException(
     
'Specified argument does not belong to the domain of this function.'
   
);
  }
  return
log($argument, $base);
}
?>