Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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!

like image 368
Adam C. Avatar asked Jan 31 '11 17:01

Adam C.


2 Answers

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.

like image 50
Benubird Avatar answered Nov 12 '22 19:11

Benubird


you can find some answers at this similar question.

like image 2
DesignFirst Avatar answered Nov 12 '22 19:11

DesignFirst