PHP實現(xiàn)的簡單異常處理類示例
本文實例講述了PHP實現(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ù)不同錯誤拋出不同異常
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錯誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
Uncaught exception com_exception with message Failed to crea
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `InternetExplorer.Application': 拒絕訪問2012-01-01
解析PHP中intval()等int轉(zhuǎn)換時的意外異常情況
本篇文章是對PHP中intval()等int轉(zhuǎn)換時的意外異常情況進行了詳細的分析介紹,需要的朋友參考下2013-06-06
php中多維數(shù)組按指定value排序的實現(xiàn)代碼
這篇文章主要介紹了php中多維數(shù)組按指定value排序的實現(xiàn)代碼,可以實現(xiàn)類似數(shù)據(jù)庫排序字段的排序效果,需要的朋友可以參考下2014-08-08
php 將字符串按大寫字母分隔成字符串?dāng)?shù)組
php 將字符串按大寫字母分隔成字符串?dāng)?shù)組,需要的朋友可以參考下。2010-04-04
php中自定義函數(shù)dump查看數(shù)組信息類似var_dump
本文為大家介紹下在php中自定義函數(shù)dump查看數(shù)組信息,具體示例如下,希望對大家有所幫助2014-01-01
PHP基于pdo的數(shù)據(jù)庫操作類【可支持mysql、sqlserver及oracle】
這篇文章主要介紹了PHP基于pdo的數(shù)據(jù)庫操作類,可實現(xiàn)基本的數(shù)據(jù)庫連接、增刪改查、關(guān)閉連接等操作,還支持針對mysql、sqlserver及oracle等數(shù)據(jù)庫的操作,需要的朋友可以參考下2018-05-05

