©
このドキュメントでは、 php中国語ネットマニュアル リリース
(PHP 5 >= 5.1.0)
Exception thrown if a value does not adhere to a defined valid data domain.
[#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);
}
?>