PHP實(shí)現(xiàn)的簡單異常處理類示例
本文實(shí)例講述了PHP實(shí)現(xiàn)的簡單異常處理類。分享給大家供大家參考,具體如下:
<?php
header('content-type:text/html;charset=UTF-8');
// 創(chuàng)建email異常處理類
class emailException extends exception
{
}
// 創(chuàng)建pwd異常處理類
class pwdException extends exception
{
public function __tostring(){
return $this->getMessage().'in file:'.$this->getFile().'on line:'.$this->getLine();
}
}
function reg($reginfo = null)
{
// 依據(jù)不同錯(cuò)誤拋出不同異常
if (empty($reginfo) || !isset($reginfo)) {
throw new Exception('參數(shù)非法');
}
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;
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP錯(cuò)誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php實(shí)現(xiàn)的CSS更新類實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)的CSS更新類及其用法實(shí)例,包括了針對模板文件的檢查、更新與替換模板文件等功能,非常實(shí)用,需要的朋友可以參考下2014-09-09
幾款免費(fèi)開源的不用數(shù)據(jù)庫的php的cms
下面的幾種內(nèi)容采集系統(tǒng)都是英文版的,全部不需使用數(shù)據(jù)庫,都是國外的免費(fèi)并且開源CMS。對中文支持如何,你自己試試吧!2010-12-12
php中array_column函數(shù)簡單實(shí)現(xiàn)方法
這篇文章主要介紹了php中array_column函數(shù)簡單實(shí)現(xiàn)方法,結(jié)合實(shí)例形式簡單分析了array_column函數(shù)的功能,并針對低版本的情況給出了array_column函數(shù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-07-07
php中修改瀏覽器的User-Agent來偽裝你的瀏覽器和操作系統(tǒng)
修改瀏覽器的User-Agent來偽裝你的瀏覽器和操作系統(tǒng),這兩種都可以得到User-Agents和IP等信息,最好配合正則表達(dá)式,對信息進(jìn)行篩選剔除。2011-07-07

