Which of the following is better to catch an error when calling a web service using 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With