Php 使用CodeIgniter时捕获SOAP错误

Php 使用CodeIgniter时捕获SOAP错误,php,codeigniter,Php,Codeigniter,我试图找到一种在CodeIgniter模型中捕获SOAP异常的方法,我搜索了几个小时,发现更多的人试图得到答案,但没有成功 创建SoapClient的新实例时,如何捕获异常? 我尝试了以下方法,但codeIgniter仍然给我提供了“遇到PHP错误”页面,在这个项目中,这在大多数情况下都是好的 class User_model extends CI_Model { public function __construct() { $this->WAPI_ser

我试图找到一种在CodeIgniter模型中捕获SOAP异常的方法,我搜索了几个小时,发现更多的人试图得到答案,但没有成功

创建SoapClient的新实例时,如何捕获异常? 我尝试了以下方法,但codeIgniter仍然给我提供了“遇到PHP错误”页面,在这个项目中,这在大多数情况下都是好的

class User_model extends CI_Model
{
    public function __construct()
    {
        $this->WAPI_service_url = 'http://api.lan/WAPITranslator/WAPITranslator.asmx?wsdl';

        try{
            $this->connection = new SoapClient($this->WAPI_service_url, array('trace' => 1, "exception" => 0));
        }
        catch(Exception $e){
            return false;
        }
    }
接下来,我会这样做:

class User_model extends CI_Model
{
    public function __construct() {
        $this->WAPI_service_url = 'http://api.lan/WAPITranslator/WAPITranslator.asmx?wsdl';

        try {
            $this->connection = new SoapClient($this->WAPI_service_url, array('trace' => 1, "exceptions" => true));
        } catch (Exception $e){
            $e->getMessage(); // get the error message and save it somewhere
            $e->getCode(); // gets the error code
        }
    }
}

不,如果连接出现问题,codeigniter仍然会给出相同的错误。在我的例子中,我强制接收SOAP请求的服务器关闭。将
SoapFault
替换为
Exception
,您应该没事了,我现在已经测试过了。这就是wierd,您是否在提到的文件中使用名称空间?如果是这样,您必须在捕获块中使用
\Exception
而不是
Exception
。不,我没有做任何特殊的事情,使用刚刚下载的codeigniter。。。