时间:2021-07-01 10:21:17 帮助过:3人阅读
具体如下:
<?php
header('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($reginfo)) {
throw new Exception('参数非法');
}
if (empty($reginfo['email'])) {
throw new emailException('邮件为空');
}
if ($reginfo['pwd'] != $reginfo['repwd']) {
throw new pwdException('两次密码不一致!');
}
}
// 接收不同异常,并针对性处理!
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 strstr 函数判断字符串是否否存在的实例代码_php基础
php中time()和mktime()方法的区别_php基础
php数组声明、遍历、数组全局变量使用小结_php基础
以上就是PHP实现异常处理类的方法的详细内容,更多请关注Gxl网其它相关文章!