/*
throw new Exception($error_message);
*/
class customExceptionClass extends Exception
{
public function errorMessage()
{
$errorMsg = 'Error on line: ' . $this->getLine() . "<br />" .
'in file ' . $this->getFile() . "<br />" .
'Error Message: ' . $this->getMessage() . "<br />";
return $errorMsg;
}
}
$email = "name#email.com";
try
{
if (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {
throw new customExceptionClass("email " . $email . " is not valid");
}
}
catch (customExceptionClass $e)
{
echo $e->errorMessage();
}
/*
run:
Error on line: 21
in file C:\xampp\htdocs\workingframe.com\test.php
Error Message: email name#email.com is not valid
*/