PHP实现的简单异常处理类示例
本文实例讲述了PHP实现的简单异常处理类。分享给大家供大家参考,具体如下:
getMessage().'infile:'.$this->getFile().'online:'.$this->getLine(); } } functionreg($reginfo=null) { //依据不同错误抛出不同异常 if(empty($reginfo)||!isset($reginfo)){ thrownewException('参数非法'); } if(empty($reginfo['email'])){ thrownewemailException('邮件为空'); } if($reginfo['pwd']!=$reginfo['repwd']){ thrownewpwdException('两次密码不一致!'); } } //接收不同异常,并针对性处理! try{ reg(array('email'=>'1078789950@qq.com','pwd'=>'123','repwd'=>'1231')); }catch(Exception$e){ echo$e->getMessage(); }catch(emailException$ee){ echo$ee->getMessage(); }catch(pwdException$ep){ echo$ep; }
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP错误与异常处理方法总结》、《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。