dongzhuji1042 2015-10-30 18:05
浏览 35
已采纳

如何访问PHP异常的内部异常

When I make __soapCall (client pointing to a WSDL) and the request is invalid in the server side, the caught exception's message is coming out as general as this:

An error occurred while executing the command definition. See the inner exception for details.

This is an example of one of my try-catch blocks:

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

When I var_dump the getTrace(), the array only points to the file and line where I make this call, which is not useful at all... It seems there is no getInnerExceptionMessage() method in the Exception class or something remotely similar to that. So how should I access that inner exception?

  • 写回答

1条回答 默认 最新

  • doujiaozhan2413 2015-10-30 18:05
    关注

    If you var_dump($e->detail), you can see the entire Exception's detail object and access the inner exception's message through the following path:

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

    You may be interested in printing more fields from this object. Here's a dump:

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

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题