(PHP 5 >= 5.1.0)
Exception thrown if a value does not adhere to a defined valid data domain.
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);
}
?>
johnny dot bojowkarz at gmail dot com (2011-07-19 03:27:43)
<?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);
}
?>