开发者

soapClient use SoapFault or Exception or both to catch Error?

开发者 https://www.devze.com 2023-02-07 13:50 出处:网络
Which of the following is better to catch an error when calling a web service us开发者_如何转开发ing SoapClent?

Which of the following is better to catch an error when calling a web service us开发者_如何转开发ing SoapClent?

try {
  $response = $client->SomeSoapRequest();
}
  catch(SoapFault $e){
}

Or:

try {
  $response = $client->SomeSoapRequest();
}
  catch(SoapFault $e){
}
  catch(Exception $e){
}

Also, I want to catch a socket timeout; will this be a SoapFault or an Exception?

Thanks!


Just catch Exception; this will also catch SoapFault. If you need to know the difference, you can check the type of the object received. Exception will also catch other non-soapfault exceptions, which you should be doing anyway. So, the answer is: the second one.


you can find some answers at this similar question.

0

精彩评论

暂无评论...
验证码 换一张
取 消