简体   繁体   English

异常的参数错误([string $ exception [,long $ code]])

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

Have been staring to this exception for while and have no clue whats going wrong. 一直盯着这个例外,并且没有任何线索是怎么回事。

Fatal Error: Wrong parameters for Exception([string $exception [, long $code ]]) 致命错误: Exception([string $exception [, long $code ]])参数错误Exception([string $exception [, long $code ]])

It seems pretty straight forward, the Exception expects a message and a optional code, though for some reason the code won't agree with me. 看起来非常简单,Exception需要一条消息和一个可选代码,但由于某些原因代码不符合我的要求。 Even when I drop the last parameter $e (for keeping the stacktrace), this same error pops up. 即使我删除最后一个参数$e (用于保持堆栈跟踪),也会弹出同样的错误。

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

Only when i omit both the code ( 0 ) and the previous exception ( $e ), the error is thrown correctly. 只有当我省略代码( 0 )和前一个异常( $e )时,才会正确抛出错误。

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

Although i never worked with SOAP technology, so just taken from SoapClient manual 虽然我从未使用过SOAP技术,所以只从SoapClient manual

The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault exception选项是一个布尔值,用于定义soap错误是否抛出SoapFault类型的异常

and soapFault syntax is soapFault语法是

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

so I will suggest you to check all the examples on manual. 所以我建议你查看手册上的所有例子。 here i got one exmaple 在这里我有一个例子

To get custom Soap Error Codes use in the catch $e->faultcode instead of $e->getCode . 要获取自定义Soap错误代码,请使用catch $e->faultcode而不是$e->getCode

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

one more example: 再举一个例子:

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(); 
        } 

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM