PHP encapsulates an exception handling class

陈政宽~
Release: 2023-03-11 20:20:01
Original
1268 people have browsed it

这篇文章主要为大家详细介绍了php封装一个异常的处理类,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了php自定义异常处理类,供大家参考,具体内容如下

一、代码

    自定义异常处理类 
  getMessage()."不是一个合法的电话号码"; $errorMsg .="
"; $errorMsg .="错误文件路径:".$this->getFile(); $errorMsg .="
"; $errorMsg .="错误代码行号:".$this-> getLine(); return $errorMsg; } } function check_tel($tel){ //自定义函数验证电话号码格式是否正确 $checkphone="/^13(\\d{9})$/"; //定义验证手机号码的正则表达式 $counts=preg_match($checkphone,$tel); //执行验证操作 return $counts; //返回验证结果 } $tel = "133891gfj"; //定义被验证的电话号码 /* 通过自定义异常处理类返回错误提示 */ try { if(check_tel($tel) !=1){ throw new TelException($tel); } }catch (TelException $e){ include_once("error.php"); } ?>
Copy after login

二、运行结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

The above is the detailed content of PHP encapsulates an exception handling class. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!