4

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 ]])

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. Even when I drop the last parameter $e (for keeping the stacktrace), this same error pops up.

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.

try {
    // ...
} catch (Exception $e) {
    throw new Exception('Client cannot be created');
}
7
  • @diEcho $this->service = new SoapClient(VHS_WSDL, array("trace" => 1)); Commented Sep 4, 2012 at 8:30
  • Currious thing though, the PHP documention php.net/manual/en/exception.construct.php is talking about the code as being a int, though, the exception is talking about a long. Commented Sep 4, 2012 at 8:33
  • have a look at the doc php.net/manual/en/language.exceptions.php Commented Sep 4, 2012 at 8:34
  • Which PHP version? Can you supply code that reproduces the issue? Commented Sep 4, 2012 at 8:37
  • 1
    The current version is 5.2.7. I found that supplying the previous exception is supported from 5.3. So I hat to delete that argument anyway, and the code wasn't really used by my code so stripped it to the working exception. Though, don't have an anwser why teh code with the $code paramater does not work. Commented Sep 4, 2012 at 14:29

1 Answer 1

1

Although i never worked with SOAP technology, so just taken from SoapClient manual

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

and soapFault syntax is

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.

<?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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.