Heim  >  Artikel  >  Backend-Entwicklung  >  yii2 try cactch没有捕获异常,为什么呢,谢谢

yii2 try cactch没有捕获异常,为什么呢,谢谢

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

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

为什么yii 抛出的异常是yiibaseErrorException ? 我的Exception 系统异常也捕获不了 Yii抛出的异常? 如何解决既能捕获系统异常也能捕获Yii的 yiibaseErrorException 异常呢?

回复内容:

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

为什么yii 抛出的异常是yiibaseErrorException ? 我的Exception 系统异常也捕获不了 Yii抛出的异常? 如何解决既能捕获系统异常也能捕获Yii的 yiibaseErrorException 异常呢?

可能是你的PHP版本太低了,记得一次PHP版本升级note里有说修复一下异常的问题;
我用PHP5.5试了,不出现你说的问题。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn