Reputation: 1023
I'm running a php script against an appliance that's worked great up until recently when a special circumstance has caused a fatal error.
$soapClient = new SoapClient("/var/www/blah/someWSDL.wsdl", array('trace'=>true, 'exceptions'=>true,'location'=>"https://hostName:8443/axl",'login' => "userName",'password'=> "password"));
$response = $soapClient->getLine(array("routePartitionName"=>"PT-INHOUSE", "pattern"=>"$row[callingPartyNumber]"));
echo "<TR><TD class='body'>" . $response->return->line->description . "</TD><TD class='body'>"
So, this will work in any situation where $response yields an output. However, there are situations where it will not (very rare). In those cases, this is generated;
Fatal error: Uncaught SoapFault exception: [soapenv:Server] Item not valid:
In reading up on the issue, it sounds like what I should be doing is "catching" the error. In the event that the fatal error occurs, I would like to bypass echoing $response->return->line->description and replace this output with text like "nothing found". Is this possible to do with an if statement, such as "if fatal error occurs, output this"? From what I've read, this is not something that is recommended. Any help is appreciated.
Upvotes: 0
Views: 72
Reputation: 4185
Generally talking, you should avoid errors by checking the conditions in which errors get thrown, and avoid these. If you cannot avoid the errors, use this construction:
try {
// code that produces errors
} catch (Exception $e) {
echo $e -> getMessage ();
echo "Nothing found.";
}
Further information: http://www.w3schools.com/php/php_exception.asp
Upvotes: 2