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

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

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

      <tfoot id='QBi5M'></tfoot>

      1. <legend id='QBi5M'><style id='QBi5M'><dir id='QBi5M'><q id='QBi5M'></q></dir></style></legend>

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

        異常捕獲:什么時(shí)候不捕獲它們?

        Exception catching: when not to catch them?(異常捕獲:什么時(shí)候不捕獲它們?)
      2. <tfoot id='ZCYSQ'></tfoot>

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

            • <bdo id='ZCYSQ'></bdo><ul id='ZCYSQ'></ul>

                <tbody id='ZCYSQ'></tbody>
              <legend id='ZCYSQ'><style id='ZCYSQ'><dir id='ZCYSQ'><q id='ZCYSQ'></q></dir></style></legend>

              <small id='ZCYSQ'></small><noframes id='ZCYSQ'>

                • 本文介紹了異常捕獲:什么時(shí)候不捕獲它們?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我在 PHP 的 Zend 框架中為我的應(yīng)用程序編寫(xiě)了許多小型庫(kù)(一堆類).我也一直在庫(kù)的方法本身中捕獲這些異常并將它們記錄到文件中.

                  I had been writing number of small libraries (bunch of classes) for my application inside PHP's Zend Framework. I had also been catching these exceptions inside the library's methods itself and logging them to a file.

                  然后突然我遇到了一個(gè)問(wèn)題,即使用這些庫(kù)的主應(yīng)用程序即使在我預(yù)計(jì)它們會(huì)因致命錯(cuò)誤而退出的情況下也不會(huì)因錯(cuò)誤而退出.這樣做的問(wèn)題是下面的代碼一直執(zhí)行到最后——它不應(yīng)該有.

                  Then suddenly I ran to an issue that my main application that was using these libraries would not quit due to errors even in situations I expected them to quit due to a fatal error. The problem with this was the code below kept executing till the end - which it should not have.

                  捕獲并記錄庫(kù)類中的大多數(shù)錯(cuò)誤(特殊情況除外)似乎不是一個(gè)好習(xí)慣.他們應(yīng)該總是按原樣拋出錯(cuò)誤?這是一個(gè)正確的假設(shè)嗎?

                  It seems like its not a good practice to catch and perhaps log majority (except in special cases) of the errors inside the library classes. They should always throw the error as it is? Would that be a correct assumption?

                  如果有人能為我回答這個(gè)問(wèn)題,我將不勝感激.

                  I'd appreciate if anyone could answer this for me.

                  推薦答案

                  在任何語(yǔ)言中,異常的一般哲學(xué)是它們傳達(dá)異常情況.您應(yīng)該相應(yīng)地使用它們.

                  The general philosophy of exceptions, in any language, is that they communicate exceptional circumstances. You should use them accordingly.

                  如果你最終用一個(gè) try 塊來(lái)包圍每個(gè)函數(shù)調(diào)用,那就有問(wèn)題了.異常被精確地設(shè)計(jì)為使錯(cuò)誤處理合乎邏輯,并且不需要程序員跟蹤所有可能的錯(cuò)誤路徑.因此,您應(yīng)該在可以有意義地對(duì)異常做出響應(yīng)的那些點(diǎn)捕獲異常.

                  If you end up surrounding every function call with a try block, something is wrong. Exceptions are precisely designed to make error handling logical and not require the programmer to track all possible error paths. Therefore, you should catch exceptions precisely at those points where you can respond meaningfully to them.

                  如果您想不出比中止和傳播錯(cuò)誤更好的方法,那么捕獲異常就沒(méi)有意義了.另一方面,如果您能夠?qū)δ承╁e(cuò)誤做出明智的反應(yīng),請(qǐng)抓住它們,然后重新拋出任何其他錯(cuò)誤.

                  If you cannot think of anything better to do than to abort and propagate the error, then there's no point catching an exception. On the other hand, if there are some errors to which you can react sensibly, catch those, and rethrow anything else.

                  一個(gè)典型的例子是,如果您要處理大量文件.如果解析邏輯中的任何地方出現(xiàn)錯(cuò)誤,您就無(wú)能為力,即使解析可能會(huì)中斷許多函數(shù)調(diào)用.但是,在主循環(huán)中,您可以嘗試解析每個(gè)文件,如果有異常,您可以捕獲該異常,跳過(guò)該文件并繼續(xù)下一個(gè).

                  A typical example is if you're processing lots of files. If there's an error anywhere inside the parsing logic, there's nothing you can do, even though parsing may go down many function calls. However, at the main loop you can try parsing each file, and if there's an exception, you catch that, skip the file and continue with the next one.

                  如果您正在編寫(xiě)一個(gè)庫(kù)函數(shù),您可能希望在整個(gè)函數(shù)周圍有一個(gè)最后的 try 塊;不過(guò),這在某種程度上取決于您.只需清楚地記錄用戶必須從您的庫(kù)中獲得哪些例外.

                  If you're writing a library function, you might want to have one final try block surrounding your entire function; that's somewhat up to you, though. Just document cleanly which exceptions the user has to expect from your library.

                  這篇關(guān)于異常捕獲:什么時(shí)候不捕獲它們?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                    <tbody id='ev5Li'></tbody>

                  <tfoot id='ev5Li'></tfoot>

                    <small id='ev5Li'></small><noframes id='ev5Li'>

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

                            主站蜘蛛池模板: 国产精品久久久久久久免费观看 | 最新伦理片 | 国产不卡一区 | 国产黄色大片在线观看 | 精品久久精品 | 成人一区二区三区在线观看 | 日韩在线不卡视频 | 久久天堂网 | 日韩av一区二区在线观看 | 午夜精品久久久久久久久久久久久 | 国产中文视频 | 成人小视频在线观看 | 人人做人人澡人人爽欧美 | 中文字幕在线一区 | 罗宾被扒开腿做同人网站 | 久草在线在线精品观看 | 黄页网址在线观看 | 午夜国产精品视频 | 欧美精品一区二区三区在线四季 | 黄视频免费观看 | 99精品欧美一区二区三区综合在线 | 97精品国产 | 野狼在线社区2017入口 | 黄色网毛片 | 夜夜艹 | 久久久国产精品一区 | 久久精品免费一区二区 | 成年人黄色免费视频 | 综合视频在线 | h视频免费在线观看 | 成人性生交a做片 | 亚洲成av片人久久久 | 国产一区久久精品 | 久久久xxx| 日韩二区三区 | 中文字幕在线观看第一页 | 国产成人精品一区二区三区在线 | 在线视频一区二区 | 日韩免费视频 | 中文字幕第5页 | 国产精品日韩一区二区 |