<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                和PHP默認的異常處理不同,ThinkPHP拋出的不是單純的錯誤信息,而是一個人性化的錯誤頁面。 ## 默認異常處理 在調試模式下,系統默認展示的錯誤頁面: ![](https://box.kancloud.cn/0ddddc3bcc3a3755e21542fd296b741f_1028x708.png) >[info]只有在調試模式下面才能顯示具體的錯誤信息,如果在部署模式下面,你可能看到的是一個簡單的提示文字,例如: ![](https://box.kancloud.cn/a770f72a8ce4bab4352927ff8b69139f_817x162.png) >[danger]#### 本著嚴謹的原則,5.0版本默認情況下會對任何錯誤(包括警告錯誤)拋出異常,如果不希望如此嚴謹的拋出異常,可以在應用公共函數文件中或者配置文件中使用`error_reporting`方法設置錯誤報錯級別(請注意,在入口文件中設置是無效的),例如: ~~~ // 異常錯誤報錯級別, error_reporting(E_ERROR | E_PARSE ); ~~~ ## 異常處理接管 框架支持異常頁面由開發者自定義類進行處理,需要配置參數`exception_handle` ~~~ // 異常處理handle類 留空使用 \think\exception\Handle 'exception_handle' => '\\app\\common\\exception\\Http', ~~~ 自定義類需要繼承`Handle`并且實現`render`方法,可以參考如下代碼: ~~~ <?php namespace app\common\exception; use Exception; use think\exception\Handle; use think\exception\HttpException; class Http extends Handle { public function render(Exception $e) { // 參數驗證錯誤 if ($e instanceof ValidateException) { return json($e->getError(), 422); } // 請求異常 if ($e instanceof HttpException && request()->isAjax()) { return response($e->getMessage(), $e->getStatusCode()); } //TODO::開發者對異常的操作 //可以在此交由系統處理 return parent::render($e); } } ~~~ >[info]需要注意的是,如果配置了'exception_handle',且沒有再次調用系統`render`的情況下,配置`http_exception_template`就不再生效,具體可以參考`Handle`類內實現的功能。 `V5.0.11`版本開始,可以通過閉包定義的方式簡化異常自定義處理,例如,上面的自定義異常類可以改為直接配置`exception_handle`參數: ~~~ 'exception_handle' => function(Exception $e){ // 參數驗證錯誤 if ($e instanceof \think\exception\ValidateException) { return json($e->getError(), 422); } // 請求異常 if ($e instanceof \think\exception\HttpException && request()->isAjax()) { return response($e->getMessage(), $e->getStatusCode()); } } ~~~ ## 部署模式異常 一旦關閉調試模式,發生錯誤后不會提示具體的錯誤信息,如果你仍然希望看到具體的錯誤信息,那么可以如下設置: ~~~ // 顯示錯誤信息 'show_error_msg' => true, ~~~ ![](https://box.kancloud.cn/b4f2c9679d0b0803d963cf5b1253db96_839x191.png) ## 異常捕獲 可以使用PHP的異常捕獲進行必要的處理,但需要注意一點,在異常捕獲中不要使用`think\Controller`類的error、success和redirect方法,因為上述三個方法會拋出`HttpResponseException`異常,從而影響正常的異常捕獲,例如: ~~~ try{ Db::name('user')->find(); $this->success('執行成功!'); }catch(\Exception $e){ $this->error('執行錯誤'); } ~~~ 應該改成 ~~~ try{ Db::name('user')->find(); }catch(\Exception $e){ $this->error('執行錯誤'); } $this->success('執行成功!'); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看