文字

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 {
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
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 )
}

用户评论:

[#1] chmielewski dot thomas at gmail dot com [2014-08-29 10:45:12]

<?php

function divide($divident, $divisor) {
    if(!is_numeric($divident) || !is_numeric($divisor)) {
        throw new InvalidArgumentException("Function accepts only numeric values");
    }
    if($divisor == 0) {
        throw new DomainException("Divisor must not be zero");
    }
    return $divident / $divisor;
}

[#2] mateusz dot charytoniuk at gmail dot com [2011-10-20 12:45:15]

<?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);
}
?>

上一篇: 下一篇: