SoapClient 使用 SoapFault 或 Exception 或两者来捕获错误?
使用 SoapClent 调用 Web 服务时,以下哪一项更能捕获错误?
try {
$response = $client->SomeSoapRequest();
}
catch(SoapFault $e){
}
或者:
try {
$response = $client->SomeSoapRequest();
}
catch(SoapFault $e){
}
catch(Exception $e){
}
另外,我想捕获套接字超时;这是 SoapFault
还是 Exception
?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需捕获异常即可;这也会捕获 SoapFault。如果需要知道区别,可以检查接收到的对象的类型。 Exception 还将捕获其他非 soapfault 异常,无论如何您都应该这样做。所以,答案是:第二个。
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.