2012-09-04 82 views
3

一直在盯着这个例外,并且没有线索发生什么错误。

Fatal Error: Wrong parameters for Exception([string $exception [, long $code ]])

似乎很直截了当,异常期待的消息和可选的代码,但由于某些原因,代码不会同意我的看法。即使当我放弃最后一个参数$e(用于保存堆栈跟踪)时,也会弹出相同的错误。

try { 
    // ... 
} catch (Exception $e) { 
    throw new Exception('Client cannot be created', 0, $e); 
} 

只有当我忽略两个密码(0)和前一个异常($e),错误是正确抛出。

try { 
    // ... 
} catch (Exception $e) { 
    throw new Exception('Client cannot be created'); 
} 
+0

什么在'try'块 – diEcho

+0

@diEcho $ this-> service = new SoapClient(VHS_WSDL,array(“trace”=> 1)); –

+0

虽然很有趣,但PHP文档http://www.php.net/manual/en/exception.construct.php正在将代码作为一个int来讨论,不过,除了长篇大论之外。 –

回答

1

虽然我从来没有与SOAP技术工作,所以只是从SoapClient manual

The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault

采取的SOAPFault语法

SoapFault::SoapFault (string $faultcode , 
         string $faultstring [, 
         string $faultactor [, 
         string $detail [, 
         string $faultname [, 
         string $headerfault ]]]]); 

,所以我会建议你检查所有的例子在手册上。在这里我得到了一个exmaple

要获得自定义肥皂错误代码使用在赶上$e->faultcode而不是$e->getCode

<?php 
try { 
    // ... 
} catch (SoapFault $e) { 
    echo $e->faultcode; 
} 
?> 

一个例子:

try { 
      $options = array( 
       'soap_version'=>SOAP_1_1, 
       'exceptions'=>true, 
       'trace'=>1, 
       'cache_wsdl'=>WSDL_CACHE_NONE 
      ); 
      $client = new SoapClient('http://www.example.com/end_point.wsdl', $options); 

     } catch (Exception $e) { 
      echo "<h2>Exception Error!</h2>"; 
      echo $e->getMessage(); 
     } 

希望它能帮助。