Maison  >  Article  >  développement back-end  >  yii2 try cactch没有捕获异常,为什么呢,谢谢

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

WBOY
WBOYoriginal
2016-09-03 00:14:101516parcourir

<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试了,不出现你说的问题。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn