一直盯着这个异常一段时间,不知道出了什么问题。
Fatal Error: Wrong parameters for
Exception([string $exception [, long $code ]])
这看起来很简单,Exception 需要一条消息和一个可选代码,但由于某些原因代码不同意我的看法。即使我删除最后一个参数 $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');
}
最佳答案
尽管我从未使用过 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 ]]]] );
所以我会建议您检查手册中的所有示例。我这里有一个例子
要获取自定义 Soap 错误代码,请在捕获中使用 $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();
}
希望对您有所帮助。
关于php - Exception([string $exception [, long $code ]]) 参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12259538/