我试图找到一种在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;
}
}
答案 0 :(得分:0)
在PHP docs之后,我会这样:
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
}
}
}