【问题标题】:How to access a PHP Exception's Inner Exception如何访问 PHP 异常的内部异常
【发布时间】:2015-10-30 18:05:24
【问题描述】:

当我创建__soapCall(指向 WSDL 的客户端)并且请求在服务器端无效时,捕获的异常消息会像这样一般:

执行命令定义时出错。有关详细信息,请参阅内部异常

这是我的 try-catch 块之一的示例:

try {
    $soapCallResult = $client->myWSDLMethod(array(...));
} catch (Exception $e) {
    echo 'Exception in myWSDLMethod: ',  $e->getMessage(), PHP_EOL;
}

当我 var_dump getTrace() 时,该数组仅指向我进行此调用的文件和行,这根本没有用...似乎Exception class 中没有getInnerExceptionMessage() 方法或与此类似的东西。那么我应该如何访问那个内部异常呢?

【问题讨论】:

    标签: php exception soap exception-handling soap-client


    【解决方案1】:

    如果你var_dump($e->detail),可以看到整个Exception的detail对象,通过以下路径访问内部异常的消息:

    $e->detail->ExceptionDetail->InnerException->Message
    

    您可能有兴趣从此对象打印更多字段。这是一个转储:

    object(stdClass)[?]
      public 'ExceptionDetail' => 
        object(stdClass)[?]
          public 'HelpLink' => null
          public 'InnerException' => 
            object(stdClass)[?]
              public 'HelpLink' => null
              public 'InnerException' => null
              public 'Message' => string 'SERVER ERROR MSG: ...' (length=?)
              public 'StackTrace' => string '   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)'... (length=?)
              public 'Type' => string 'System.Data.SqlClient.SqlException' (length=34)
          public 'Message' => string 'An error occurred while executing the command definition. See the inner exception for details.' (length=94)
          ...
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      相关资源
      最近更新 更多