PHP 7.0.6 Released

The DomainException class

(PHP 5 >= 5.1.0, PHP 7)

Introduction

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

Class synopsis

DomainException extends LogicException {
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Inherited methods */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed 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 )
}

User Contributed Notes

mateusz dot charytoniuk at gmail dot com
4 years ago
<?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);
}
?>
chmielewski dot thomas at gmail dot com
1 year ago
<?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;
}
To Top