Home > Article > Backend Development > yii2 try cactch does not catch the exception, why, thank you
<code>/** * 获得银行卡 * @param array $data * @return string */ public function getBank($data) { try { $client = $this->getClient(); $params = $this->getConnectParams(array('username' => $data['username'])); $response = $client->GetBank($params); $return_json = $response->GetBankResult; $return_arr = json_decode($return_json) ; $status = $return_arr->result ; } catch (\Exception $e) { self::addLog($e); $status = 'error'; } } </code>
Why is the exception thrown by Yii yiibaseErrorException? My Exception system exception cannot catch the exception thrown by Yii? How to solve the problem of catching both system exceptions and Yii's yiibaseErrorException exception?
<code>/** * 获得银行卡 * @param array $data * @return string */ public function getBank($data) { try { $client = $this->getClient(); $params = $this->getConnectParams(array('username' => $data['username'])); $response = $client->GetBank($params); $return_json = $response->GetBankResult; $return_arr = json_decode($return_json) ; $status = $return_arr->result ; } catch (\Exception $e) { self::addLog($e); $status = 'error'; } } </code>
Why is the exception thrown by Yii yiibaseErrorException? My Exception system exception cannot catch the exception thrown by Yii? How to solve the problem of catching both system exceptions and Yii's yiibaseErrorException exception?
It may be that your PHP version is too low. I remember that the PHP version upgrade note mentioned fixing abnormal problems;
I tried it with PHP5.5, and the problem you mentioned did not occur.