“`<?phpheader(‘content-type:text/html;charset=UTF-8′);// 创建email异常处理类class emailException extends exception{}// 创建pwd异常处理类class pwdException extends exception{ public function __tostring(){ return $this->getMessage().’in file:’.$this->getFile().’on line:’.$this->getLine(); }}function reg($reginfo = null){ // 依据不同错误抛出不同异常 if (empty($reginfo) || !isset(本文来源gaodai$ma#com搞$$代**码)网8搞代gaodaima码$reginfo)) { throw new Exception(‘参数非法’); } if (empty($reginfo[’email’])) { throw new emailException(‘邮件为空’); } if ($reginfo[‘pwd’] != $reginfo[‘repwd’]) { throw new pwdException(‘两次密码不一致!’); }}// 接收不同异常,并针对性处理!try { reg(array(’email’ => ‘[email protected]’, ‘pwd’ => ‘123’, ‘repwd’ => ‘1231’ ));} catch (Exception $e) { echo $e ->getMessage();} catch (emailException $ee) { echo $ee ->getMessage();} catch (pwdException $ep) { echo $ep;}“`
php异常处理类
