Specific as follows:
<?php
Header (' Content-type:text/html;charset=utf-8 ');
Create an email exception handling class
Class Emailexception extends exception
{
}
Creating the PWD Exception handling class
Class Pwdexception extends exception
{
Public Function __tostring () {
return $this->getmessage (). ' In file: '. $this->getfile (). ' On line: '. $this->getline ();
}
}
function reg ($reginfo = null)
{
Throw different exceptions based on different errors
if (Empty ($reginfo) | |!isset ($reginfo)) {
throw new Exception (' argument illegal ');
}
if (Empty ($reginfo [' email ')]) {
throw new Emailexception (' message is empty ');
}
if ($reginfo [' pwd ']! = $reginfo [' repwd ']) {
throw new Pwdexception (' two times password inconsistent! ‘);
}
}
Receive different exceptions and deal with them in a targeted direction!
try {
Reg (' Email ' = ' [email protected] ', ' pwd ' = ' 123 ', ' repwd ' = ' 1231 '));
} catch (Exception $e) {
echo $e->getmessage ();
} catch (Emailexception $ee) {
echo $ee->getmessage ();
} catch (Pwdexception $ep) {
Echo $ep;
}
Beijing website Construction
Examples of simple exception handling classes implemented by PHP