欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實現(xiàn)的簡單異常處理類示例

 更新時間:2017年05月04日 09:50:30   作者:yhdsir  
這篇文章主要介紹了PHP實現(xiàn)的簡單異常處理類,結合具體實例形式分析了php基于面向對象技術實現(xiàn)異常處理操作的相關實現(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;
}

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP錯誤與異常處理方法總結》、《php字符串(string)用法總結》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運算與運算符用法總結》、《PHP網(wǎng)絡編程技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論