<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ### 拋出異常 > Lying能捕獲全局的錯誤/異常,如果你的代碼拋出了異常并且沒有手動捕獲,Lying將會捕獲它們并且做相應處理。 在程序中手動拋出異常: ~~~php throw new \lying\exception\HttpException('我的異常', 400); //httpCode被設置為400 throw new \Exception('我的異常'); //httpCode被設置為500 ~~~ * 如果拋出的異常類繼承自`\lying\exception\HttpException`,那么http返回碼會被設置成異常的錯誤碼; * 如果拋出的異常類不是繼承自`\lying\exception\HttpException`,那么http返回碼會被設置成`500`; ### 默認異常處理 當你沒有手動注冊異常處理程序時,默認會這樣處理: * debug配置為true時,顯示 ![exception](https://box.kancloud.cn/de7688d922728a10908405ee7b49f212_685x246.png) * debug配置為false時,只顯示`An internal server error occurred.` ### 自定義異常處理 > Lying的異常/錯誤其實是一個全局事件,你完全可以注冊事件來替代Lying默認的錯誤處理 事件處理程序接受一個時間參數`$event`,是`lying\event\ExceptionEvent`的實例,所以可以這樣來獲取異常: ~~~php function handle($event) { $exception = $event->e; } ~~~ #### 在配置文件注冊錯誤處理 ~~~php //全局事件 'hook' => [ 'events' => [ ['frameworkError', function ($event) { //這里設置你的錯誤處理程序,例如: Lying::$maker->dispatch->run('error/error/handle', ['event'=>$event]); //執行error模塊,ErrorCtrl控制器,handle方法 return false; //返回false之后,隊列后面的事件就不再處理 }], //注冊自定義全局錯誤處理 ], ], ~~~ 或者這樣 ~~~php 'hook' => [ 'events' => [ ['frameworkError', ['ErrorHandle', 'run']], //注冊自定義全局錯誤處理,執行`ErrorHandle`類的靜態方法`run` ], ], ~~~ > 配置文件注冊的錯誤處理事件是全局的 #### 在程序中注冊錯誤處理 假設某個控制器需要特殊的錯誤處理,那么除了注冊全局錯誤處理,也可以這樣: ~~~php <?php namespace module\index\controller; use lying\service\Controller; /** * Class IndexCtrl * @package module\index\controller */ class IndexCtrl extends Controller { public function init() { parent::init(); \Lying::$maker->hook->on(\Lying::EVENT_FRAMEWORK_ERROR, function ($event) { $exception = $event->e; //獲取拋出的異常 \Lying::$maker->response()->setContent('出錯了')->send(); //顯示錯誤信息 return false; //事件隊列后面的事件不再執行 }, null, false); //注冊到事件隊列最前面 } /** * 首頁 * @return string */ public function index() { return $this->render(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看