Page 1 of 1

help with code

Posted: Tue Dec 22, 2009 4:51 am
by indian98476
<?php

class customException extends Exception
{
public function errorMessage()
{
//error message
$errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
.': <b><i>'.$this->getMessage().'</b></i> is not a valid E-Mail address';
return $errorMsg;
}
}

$email = "someone@example.com";

try
{
//check if
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
{
//throw exception if email is not valid
throw new customException($email);
}
//check for "example" in mail address
if(strpos($email, "example") !== FALSE)
{
throw new Exception("$email is an example e-mail.<br />");
}
}

catch (customException $e)
{
echo $e->errorMessage();
}

catch(Exception $e)
{
echo $e->getMessage();
}
?>

how """"" $this->getMessage() """"" gets assigned the value of $email???

Re: help with code

Posted: Tue Dec 22, 2009 4:55 am
by indian98476
is it because the new custom exception is thrown first which throws the $email right?