Home  >  Article  >  Backend Development  >  yii2 try cactch does not catch the exception, why, thank you

yii2 try cactch does not catch the exception, why, thank you

WBOY
WBOYOriginal
2016-09-03 00:14:101516browse

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

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn