久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <tfoot id='59BPO'></tfoot>
    1. <legend id='59BPO'><style id='59BPO'><dir id='59BPO'><q id='59BPO'></q></dir></style></legend>
      <i id='59BPO'><tr id='59BPO'><dt id='59BPO'><q id='59BPO'><span id='59BPO'><b id='59BPO'><form id='59BPO'><ins id='59BPO'></ins><ul id='59BPO'></ul><sub id='59BPO'></sub></form><legend id='59BPO'></legend><bdo id='59BPO'><pre id='59BPO'><center id='59BPO'></center></pre></bdo></b><th id='59BPO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='59BPO'><tfoot id='59BPO'></tfoot><dl id='59BPO'><fieldset id='59BPO'></fieldset></dl></div>

      <small id='59BPO'></small><noframes id='59BPO'>

          <bdo id='59BPO'></bdo><ul id='59BPO'></ul>
      1. PHP 錯誤處理:die() Vs trigger_error() Vs throw Exception

        PHP Error handling: die() Vs trigger_error() Vs throw Exception(PHP 錯誤處理:die() Vs trigger_error() Vs throw Exception)
            1. <legend id='eRri5'><style id='eRri5'><dir id='eRri5'><q id='eRri5'></q></dir></style></legend>

                <tfoot id='eRri5'></tfoot>

              1. <small id='eRri5'></small><noframes id='eRri5'>

                  <bdo id='eRri5'></bdo><ul id='eRri5'></ul>
                  <i id='eRri5'><tr id='eRri5'><dt id='eRri5'><q id='eRri5'><span id='eRri5'><b id='eRri5'><form id='eRri5'><ins id='eRri5'></ins><ul id='eRri5'></ul><sub id='eRri5'></sub></form><legend id='eRri5'></legend><bdo id='eRri5'><pre id='eRri5'><center id='eRri5'></center></pre></bdo></b><th id='eRri5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eRri5'><tfoot id='eRri5'></tfoot><dl id='eRri5'><fieldset id='eRri5'></fieldset></dl></div>
                    <tbody id='eRri5'></tbody>

                  本文介紹了PHP 錯誤處理:die() Vs trigger_error() Vs throw Exception的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  關于 PHP 中的錯誤處理——據我所知有 3 種樣式:

                  In regards to Error handling in PHP -- As far I know there are 3 styles:

                  1. die()exit() 樣式:

                  $con = mysql_connect("localhost","root","password");
                  
                  if (!$con) {
                   die('Could not connect: ' . mysql_error());
                  }
                  

                • 拋出異常樣式:

                   if (!function_exists('curl_init')) {
                  
                        throw new Exception('need the CURL PHP extension. 
                                             Recomplie PHP with curl');
                      }
                  

                • trigger_error() 樣式:

                  if(!is_array($config) && isset($config)) {
                          trigger_error('Error: config is not an array or is not set', E_USER_ERROR);
                      }
                  

                • 現在,在 PHP 手冊中,所有三種方法都使用了.

                  Now, in the PHP manual all three methods are used.

                  • 我想知道我應該更喜歡哪種風格&為什么?

                  • What I want to know is which style should I prefer & why?

                  這 3 種是相互替代嗎?因此可以互換使用嗎?

                  Are these 3 drop in replacements of each other & therefore can be used interchangeably?

                  有點 OT:是我還是所有人都認為 PHP 錯誤處理選項太多以至于讓 php 開發人員感到困惑?

                  Slightly OT: Is it just me or everyone thinks PHP error handling options are just too many to the extent it confuses php developers?

                  推薦答案

                  第一個不應該在生產代碼中使用,因為它傳輸與最終用戶無關的信息(用戶無法對 做任何事情"無法連接到數據庫").

                  The first one should never be used in production code, since it's transporting information irrelevant to end-users (a user can't do anything about "Cannot connect to database").

                  如果您知道在某個關鍵代碼點,您的應用程序可能會失敗,并且您希望您的代碼在多個調用級別之間恢復,那么您就會拋出異常.

                  You throw Exceptions if you know that at a certain critical code point, your application can fail and you want your code to recover across multiple call-levels.

                  trigger_error() 可讓您細粒度的錯誤報告(通過使用不同級別的錯誤消息)并且您可以對最終用戶隱藏這些錯誤(使用 set_error_handler()) 但在測試過程中仍然顯示給你.

                  trigger_error() lets you fine-grain error reporting (by using different levels of error messages) and you can hide those errors from end-users (using set_error_handler()) but still have them be displayed to you during testing.

                  此外,trigger_error() 可以生成在開發過程中很重要的非致命消息,可以使用自定義錯誤處理程序在生產代碼中抑制這些消息.您也可以產生致命錯誤 (E_USER_ERROR),但這些錯誤是不可恢復的.如果您觸發其中之一,程序執行將在該點停止.這就是為什么,對于致命錯誤,應該使用異常.這樣,您就可以更好地控制程序的流程:

                  Also trigger_error() can produce non-fatal messages important during development that can be suppressed in production code using a custom error handler. You can produce fatal errors, too (E_USER_ERROR) but those aren't recoverable. If you trigger one of those, program execution stops at that point. This is why, for fatal errors, Exceptions should be used. This way, you'll have more control over your program's flow:

                  // Example (pseudo-code for db queries):
                  
                  $db->query('START TRANSACTION');
                  
                  try {
                      while ($row = gather_data()) {
                         $db->query('INSERT INTO `table` (`foo`,`bar`) VALUES(?,?)', ...);
                      }
                      $db->query('COMMIT');
                  } catch(Exception $e) {
                      $db->query('ROLLBACK');
                  }
                  

                  在這里,如果 gather_data() 只是簡單的嘶嘶聲(使用 E_USER_ERRORdie()),則有機會,之前的 INSERT 語句會將其添加到您的數據庫中,即使不需要,您也無法控制接下來會發生什么.

                  Here, if gather_data() just plain croaked (using E_USER_ERROR or die()) there's a chance, previous INSERT statements would have made it into your database, even if not desired and you'd have no control over what's to happen next.

                  這篇關于PHP 錯誤處理:die() Vs trigger_error() Vs throw Exception的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                    <tbody id='IkIGg'></tbody>

                        <i id='IkIGg'><tr id='IkIGg'><dt id='IkIGg'><q id='IkIGg'><span id='IkIGg'><b id='IkIGg'><form id='IkIGg'><ins id='IkIGg'></ins><ul id='IkIGg'></ul><sub id='IkIGg'></sub></form><legend id='IkIGg'></legend><bdo id='IkIGg'><pre id='IkIGg'><center id='IkIGg'></center></pre></bdo></b><th id='IkIGg'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IkIGg'><tfoot id='IkIGg'></tfoot><dl id='IkIGg'><fieldset id='IkIGg'></fieldset></dl></div>

                          <legend id='IkIGg'><style id='IkIGg'><dir id='IkIGg'><q id='IkIGg'></q></dir></style></legend>
                        • <tfoot id='IkIGg'></tfoot>

                        • <small id='IkIGg'></small><noframes id='IkIGg'>

                            <bdo id='IkIGg'></bdo><ul id='IkIGg'></ul>

                          • 主站蜘蛛池模板: 国产精品欧美一区二区三区不卡 | 中文区中文字幕免费看 | 成人欧美一区二区三区在线播放 | 国产精品久久毛片av大全日韩 | 国产日韩欧美中文字幕 | 日韩中文字幕在线播放 | 亚洲国产精品一区二区第一页 | 欧美一a一片一级一片 | 精品久久久999 | 国产精品久久久久久一级毛片 | 伊人电影院av | www亚洲免费国内精品 | 黄片毛片| 国产91丝袜在线熟 | 日本一区二区高清不卡 | 91麻豆精品国产91久久久久久久久 | 精品国产乱码久久久久久果冻传媒 | 成人午夜精品一区二区三区 | 一区二区在线 | 免费在线观看一区二区 | 国产精品视频999 | 国产精品久久久久久久久久久久冷 | 福利视频1000 | 欧美激情欧美激情在线五月 | 精品国产精品三级精品av网址 | www视频在线观看 | 在线成人精品视频 | 一级在线免费观看 | 一区二区不卡视频 | 久久av网站 | 国产1区2区| av天空| 久久久久久高潮国产精品视 | 精品国产乱码久久久久久丨区2区 | 欧美激情一区 | 久久视频精品 | 久久久久国产一区二区三区 | 中文字幕一区二区在线观看 | 中文在线一区 | 国产一级毛片精品完整视频版 | 久久国产区 |