class customException extends Exception { public function errorMessage() { //error message $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile() .': <b>'.$this->getMessage().'</b> '; return $errorMsg; } } try { throw new customException("error le "); } catch (customException $e) { //display custom message echo $e->errorMessage(); } ?>