久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      PHP出現異常該怎么辦

      本篇文章給大家介紹一下解決PHP出現異常的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

      PHP出現異常該怎么辦

      PHP出現異常該怎么辦

      <?php /****************************************************  * php處理異常  * try中不主動throw,會先出現PHP的系統(tǒng)錯誤  ****************************************************/ header("content-type:test/html:charset=utf-8"); error_reporting(-1); try {     $num1 = 3;     $num2 = 0;     if ($num2 == 0) {         throw new Exception("自定義錯誤");     } else {         $res = $num1 / $num2;     }  } catch (Exception $e) {     echo $e->getMessage();     // die(); // 終止異常 } /******************************************************  * php+mysql+pdo  *****************************************************/ try {     $pdo = new PDO("mysql:host=localhost;dbname=mysql", "root", ""); } catch (PDOException $e) {     echo $e->getMessage();     // die(); // 終止異常 } /******************************************************  * php+文件異常  *****************************************************/  /**  * PHP 讀取大文件 SplFileObject :  * https://blog.csdn.net/ekliu/article/details/8855907  */ // SqlFileObject相對于傳統(tǒng)的open($filename, 'r')產生的對象的優(yōu)點在于不需要打開文件句柄  不需要關閉句柄更加的方便 $handle = new SplFileObject("sid_list.txt"); while (!$handle->eof()) {     $item = $handle->fgets(); }  try {     $pdo = new SplFileObject("text.txt", "r");     echo "read File"; } catch (Exception $e) {     echo $e->getMessage();     // die(); // 終止異常 } /******************************************************  * php異常 嵌套  *****************************************************/ try {     throw new Exception("測試異常1"); } catch (Exception $e) {     echo $e->getMessage();     // die(); // 終止異常     try {         throw new Exception("測試異常2");     } catch (Exception $e) {         echo $e->getMessage();     } }  /******************************************************  * php異常 自定義異常封裝  *****************************************************/ class MyException extends Exception {     public function __construct($message = "", $code = 0, $previous = null)     {         parent::__construct($message, $code, $previous);     }      public function __toString()     {         $message = "<h2>出現異常,如下:</h2>";         $message .= "<p>" . __CLASS__ . "[{$this->code}:{$this->message}]</p>";         return $message;     }      /****************自定義異常方法***************/     public function test()     {         echo "這是自定義錯誤";     }      public function stop()     {         exit("異常 end...");     } }  // 開始調用 MyException try {     echo "出現異常啦";     throw new MyException("測試自定義異常", 3); } catch (MyException $e) {     echo $e->getMessage(); }  // 嵌套使用 MyException 與 Exception (沒有順序) try {     throw new MyException("測試自定義異常"); } catch (Exception $e) {     echo $e->getMessage(); } catch (MyException $e) {     echo $e->getMessage(); }  /******************************************************  * php異常 自定義異常封裝    文件  *****************************************************/ class FileException extends Exception {     public function getDetails()     {         switch ($this->code) {             case 0:                 return "沒有提供文件";                 break;             case 1:                 return "文件不存在";                 break;             case 2:                 return "不是一個文件";                 break;             case 3:                 return "文件不可寫";                 break;             case 4:                 return "非法文件的操作模式";                 break;         }     } }  class WriteData {     private $_message = "";     private $_fp = null;      public function __construct($filename = null, $mode = "w")     {         $this->_message = "文件:{$filename} ; 模式:{$mode}";         if (empty($filename)) throw new FileException($this->_message, 0);         if (!file_exists($filename)) throw new FileException($this->_message, 1);         if (!is_file($filename)) throw new FileException($this->_message, 2);         // is_writable — 判斷給定的文件名是否可寫         if (!is_writable($filename)) throw new FileException($this->_message, 3);         if (!in_array($mode, array("w", "w+", "a", "a         +"))) throw new FileException($this->_message, 4);          $this->_fp = fopen($filename, $mode);     }      public function write($data)     {         if (@!fwrite($this->_fp, $data . PHP_EOL)) throw new FileException($this->_message, 5);     }      public function close()     {         if ($this->_fp) {             if (!fclose($this->_fp)) throw new FileException($this->_message, 6);             $this->_fp = null;          }     }      public function __destruct()     {         $this->close();     } }

      推薦學習:php視頻教程

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號