人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動(dòng)態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁(yè)      樂(lè)道系統(tǒng)FAQ      PHP實(shí)現(xiàn)的簡(jiǎn)單異常處理類(lèi)示例

PHP實(shí)現(xiàn)的簡(jiǎn)單異常處理類(lèi)示例

標(biāo)簽: 發(fā)布日期:2017-05-04 00:00:00 290

本文實(shí)例講述了PHP實(shí)現(xiàn)的簡(jiǎn)單異常處理類(lèi)。分享給大家供大家參考,具體如下:

<?php
header('content-type:text/html;charset=UTF-8');
// 創(chuàng)建email異常處理類(lèi)
class emailException extends exception
{
}
// 創(chuàng)建pwd異常處理類(lèi)
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('兩次密碼不一致!');
  }
}
// 接收不同異常,并針對(duì)性處理!
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;
}