note 105380 modified in soapclient.dorequest by danbrown
| From: | danbrown@php.net | Date: | Sat, 13 Aug 2011 15:45:27 +0000 |
| Subject: | note 105380 modified in soapclient.dorequest by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182468@lists.php.net to get a copy of this message | ||
Note that the SoapClient.__doRequest() method circumvents the throwing of SoapFault exceptions.
Specifically, if you call the __doRequest() method and it fails, it would normally throw a SoapFault
exception. However, the __doRequest() method doesn't actually throw the exception. Instead,
the exception is saved in a class attribute called SoapFault.__soap_fault, and is actually thrown
AFTER the __doRequest method completes (but the call stack will show that the exception was created
inside the __doRequest method.
I successfully used the following code to query the locally cached exception object that was not
thrown:
<?php
$exception = null;
try {
$result = parent::__doRequest($request, $location, $action, $version, $one_way);
}
catch (SoapFault $sf) {
//this code was not reached
$exception = $sf;
}
catch (Exception $e) {
//nor was this code reached either
$exception = $e;
}
if((isset($this->__soap_fault)) && ($this->__soap_fault != null)) {
//this is where the exception from __doRequest is stored
$exception = $this->__soap_fault;
}
//decide what to do about the exception here
// [enter code here]
//or throw the exception
if($exception != null) {
throw $exception;
}
//note: you may want to unset the __soap_fault value if you don't want it thrown again up the
call stack
?>
--was--
Note that the SoapClient.__doRequest() method circumvents the throwing of SoapFault exceptions.
Specifically, if you call the __doRequest() method and it fails, it would normally throw a SoapFault
exception. However, the __doRequest() method doesn't actually throw the exception. Instead,
the exception is saved in a class attribute called SoapFault.__soap_fault, and is actually thrown
AFTER the __doRequest method completes (but the call stack will show that the exception was created
inside the __doRequest method.
I successfully used the following code to query the locally cached exception object that was not
thrown:
$exception = null;
try {
$result = parent::__doRequest($request, $location, $action, $version, $one_way);
}
catch (SoapFault $sf) {
//this code was not reached
$exception = $sf;
}
catch (Exception $e) {
//nor was this code reached either
$exception = $e;
}
if((isset($this->__soap_fault)) && ($this->__soap_fault != null)) {
//this is where the exception from __doRequest is stored
$exception = $this->__soap_fault;
}
//decide what to do about the exception here
// [enter code here]
//or throw the exception
if($exception != null) {
throw $exception;
}
//note: you may want to unset the __soap_fault value if you don't want it thrown again up the
call stack
http://php.net/manual/en/soapclient.dorequest.php