<?php
class customException extends Exception
  {
  public function displayError()
    {
    //error message
    $MsgErr= '<b>Custom message </b>: Error on line '.$this->getLine().' in '.$this->getFile()
    .'<b>'.$this->getMessage();
    return  $MsgErr;
    }
  }
//throw excepetion inside a method
function Test($count)
  {
  if($count<5)
    {
    return true;
	}
  
  }

try
  {
  //check if
  if(Test(3))
    {
    //throwing custom exception
    throw new customException();
    }
  }

catch (customException $e)
  {
  //display custom message
  echo $e->displayError();
  }
?> 