<?PHPHeader(' Content-type:text/html;charset=utf-8 ');//Create an email exception handling classclassEmailexceptionextends Exception{}//creating the PWD exception handling classclassPwdexceptionextends Exception{ Public function__tostring () {return $this->getmessage (). ' In file: '.$this->getfile (). ' On line: '.$this-GetLine (); }}functionReg$reginfo=NULL){ //throw different exceptions based on different errors if(Empty($reginfo) || !isset($reginfo)) { Throw New Exception(' argument is illegal '); } if(Empty($reginfo[' Email '])) { Throw NewEmailexception (' message is empty '); } if($reginfo[' pwd ']! =$reginfo[' Repwd ']) { Throw NewPwdexception (' two times password inconsistent! ‘); }}//receive different exceptions and deal with them in a targeted direction! Try{reg (Array(' Email ' = ' [email protected] ', ' pwd ' = ' 123 ', ' repwd ' and ' 1231 ' ));} Catch(Exception $e) { Echo $e-getMessage ();} Catch(emailexception$ee) { Echo $ee-getMessage ();} Catch(pwdexception$ep) { Echo $ep;}
PHP Exception Handling Classes