soapClient use SoapFault or Exception or both to catch Error?
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.
精彩评论