問題描述
我是 PHP 異常處理和 SOAP 的新手.出于某種原因,我無法捕獲 SoapFault.我不知道為什么.肥皂服務(wù)器不是我的.
I am new to PHP exception handling and SOAP. For some reason I cannot catch a SoapFault. I don't know why. The soap server is not mine.
try {
$contact_id = $objSoapClient->getContactIdFromVisitorId('12345');
}
catch (SoapFault $sf) {
echo "Soapfault";
}
catch (Exception $e) {
echo "Exception";
}
我故意傳入錯(cuò)誤 ID 12345.當(dāng)我啟用錯(cuò)誤時(shí),我看到以下消息 SoapFault 異常:[SOAP-ENV:Client] Invalid Visitor ID
.但是,我的 catch SoapFault 塊和我的 catch Exception 塊都被擊中.為什么?
I am purposely passing in the bad id 12345. When I enable errors I see the following message SoapFault exception: [SOAP-ENV:Client] Invalid Visitor ID
. However, my catch SoapFault block nor my catch Exception block ever get hit. Why?
推薦答案
問題出在我的 SoapClient 聲明上.必須設(shè)置一個(gè)異常參數(shù)才能觸發(fā)異常.
The problem turned out to be my SoapClient declaration. There is an exceptions parameter that must be set in order for the exceptions to trigger.
$objSoapClient = new SoapClient('https://mywebservice.com/foo.wsdl', array(
"trace" => false,
"exceptions" => true, // <-------------- This!!!
'login' => 'username', //username
'password' => 'password', //password
'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE
));
這篇關(guān)于PHP SoapFault 沒有被異常處理程序捕獲的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!