Exception([string$Exception[,long$code]])的参数错误


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

已经关注这个异常一段时间了,不知道出了什么问题。

致命错误: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 中获取

exceptions选项是一个布尔值,用于定义soap是否出错抛出SoapFault 类型的异常

soapFault语法为

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

所以我建议你检查一下手册上的所有例子。我有一个以前的

要获得自定义Soap错误代码,请在catch中使用$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(); 
        } 

希望能有所帮助。