如何解析异常错误

时间:2014-08-12 09:52:33

标签: php exception-handling

我正在使用肥皂。当我打电话时,我使用了try {} catch {}块。我想将异常错误保存到数据库中。为了美化代码,我将错误解析为我的另一个函数,这里是样本:

$paramis = array(
                'client' => '225',
                'film_id' => '612',
                'booking' => '2016-02-28',
                'persons' => 1
            );
$puri = 'http://www.filmonschedule.com/Portal/break.asmx?WSDL';
$client = new SoapClient($puri, array('trace' => 1, 'exceptions' => 1));
//var_dump($client);

try {
    $resp = $client->__soapCall('getFilmToBook', array('parameters' => $paramis));
} catch (Exception $e) {
    printErrorMu($e);
}

function printErrorMu($e)
{
    print_r($e);
}

这是输出printErrorMu($ e)

SoapFault Object
(
    [message:protected] => System.Web.Services.Protocols.SoapException: No Schedule
   at Portal.Break.getFilmToBook(String portalName, String client, String film_id, String booking, String persons)
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /var/www/myfilm/test.php
    [line:protected] => 245
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /var/www/myfilm/test.php
                    [line] => 245
                    [function] => __soapCall
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => getFilmToBook
                            [1] => Array
                                (
                                    [parameters] => Array
                                        (
                                            [client] => 225
                                            [film_id] => 612
                                            [booking] => 2016-02-28
                                            [persons] => 1
                                        )

                                )

                        )

                )

        )

    [previous:Exception:private] => 
    [faultstring] => System.Web.Services.Protocols.SoapException: No Schedule
   at Portal.Break.getFilmToBook(String portalName, String client, String film_id, String booking, String persons
    [faultcode] => soap:Server
    [faultactor] => http://www.filmonschedule.com/Portal/break.asmx
    [detail] => stdClass Object
        (
            [exceptionInfo] => No schedule for this booking request
        )

)

但我无法在函数printErrorMu($ e)中读取参数作为对象/数组。如何将参数转换为数组或作为对象,以便我可以访问属性/键的这些值([message:protected] [string:Exception:private] [code:protected] [file:protected] [line:protected] [trace :例外:私人] [上一篇:例外:私人])?

谢谢。

1 个答案:

答案 0 :(得分:1)

为什么你不能?使用SoapFault methods

$e->getMessage();
$e->getPrevious();
...