drghhp8706 2012-05-07 21:55
浏览 90
已采纳

Netbeans可以通过XDebug报告PHP异常吗?

I have installed NB 7.1, WAMPP 1.7.7 (with PHP 5.3.8) and XDebug 2.1.4. I can inspect variables on breakpoints, ok. But if exception occurs then Netbeans dont know about this, while browser show xdebug-formatted callstack. NB still thinks "netbeans-xdebug" is "running". So my question is: can Netbeans report a PHP exception?


Regards to @Andy's solution

I prepare this code for testing:

<?php

function exceptionHandler($ex) {
    echo 'Uncaught exception: ', $ex->getMessage(), "
"; // BREAKPOINT
}
set_exception_handler('exceptionHandler');

function errorHandler($errno, $errstr, $errfile, $errline) {
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('errorHandler');

throw new Exception;
phpinfo();

?>

Netbeans stops and report on my breakpoint, so one problem solved. But NB immadietly show alert titled "Socket Exception" with text:

Socket Exception occured

If you have ane Watches, try to remove them and restart debugger. If removing Watches doesn't help or you don't have any Watches, please file an issue and provide the exact steps to reproduce your problem. Please attach the IDE log. Attaching your project would also be very helpful.

I think that PHP terminates when exception occurs, so xdebug must stop and Netbeans loses dubbuging data.

  • 写回答

2条回答 默认 最新

  • douya8978 2012-05-07 22:27
    关注

    When you start Debug mode in Netbeans and an unhandled exception gets through then it outputs to your browser just like it would if you weren't running a debugger.

    Netbeans doesn't magically catch them. i.e. you can't analyze them the same way you can look at the contents of variables.

    The "netbeans-xdebug" is "running" still shows up because it is in fact still running and will continue to run until you stop it yourself or the debug session has some serious error occur, which probably won't be php related. Usually if a major error occurs you'll get some popup window. If you stop it yourself then netbeans will create a new tab in your browser saying the xdebug session has ended.

    If you hit refresh in your browser then netbeans will catch the request and analyze it and if you've setup break points it will stop at the break points. After that request has been serviced, if you hit refresh again, netbeans will keep catching any requests that come in.

    Edit : One thing I found on the xdebug site that might help you in a way with exceptions in the following option.

    xdebug.show_exception_trace
     Type: integer, Default value: 0 
    When this setting is set to 1, Xdebug will show a stack trace whenever 
    an exception is raised - even if this exception is actually caught.
    

    You can set this option in your php.ini file in the xdebug section.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 高有偿提问!求优化设计微信小程序
  • ¥15 matlab在安装时报错 无法找到入口 无法定位程序输入点
  • ¥15 收益高的广告联盟有哪些
  • ¥15 Android Studio webview 的使用问题, 播放器横屏全屏
  • ¥15 删掉jdk后重新下载,Java web所需要的eclipse无法使用
  • ¥15 uniapp正式环境中通过webapi将本地数据推送到设备出现的跨域问题
  • ¥15 xui建立节点,显示错误
  • ¥15 关于#单片机#的问题:开始、复位、十进制的功能可以实现,但是切换八进制的功能无法实现(按下按键也没有效果),把初始状态调成八进制,也是八进制可以实现但是切换到十进制不行(相关搜索:汇编语言|计数器)
  • ¥15 VINS-Mono或Fusion中feature_manager中estimated_depth是特征的深度还是逆深度?
  • ¥15 谷歌浏览器如何备份抖音网页数据