yii2 try cactch没有捕获异常,为什么呢,谢谢 [ 2.0 版本 ]
/**
* 获得银行卡
* @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';
    }
}
程序直接在GetBank处报错,没有捕获到异常,
SoapFault
Function ("GetBank") is not a valid method for this service
共 5 个回答
- 
 - 
 - 
 - 
 - 

catch (Exception $e)
改成
catch (\Exception $e)
即可因为\Exception 是yii所有异常的基类。而你写的Exception可能是上文use的某个命名空间的Exception。然而这个Exception和getBank方法里抛出的异常,不是同一个异常类。所以捕获不到。
参见:https://taoliujun.github.io/2017/yii-can-not-catch-exception/
 
wuxing164
            注册时间:2015-04-07
最后登录:2016-04-20
在线时长:13小时49分
    最后登录:2016-04-20
在线时长:13小时49分
- 粉丝5
 - 金钱15
 - 威望10
 - 积分245