简体   繁体   English

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

[英]Can Netbeans report a PHP exception through XDebug?

I have installed NB 7.1, WAMPP 1.7.7 (with PHP 5.3.8) and XDebug 2.1.4. 我已经安装了NB 7.1,WAMPP 1.7.7(使用PHP 5.3.8)和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. 但是,如果发生异常,则Netbeans对此一无所知,而浏览器则显示xdebug格式的调用栈。 NB still thinks "netbeans-xdebug" is "running". NB仍然认为“ netbeans-xdebug”正在“运行”。 So my question is: can Netbeans report a PHP exception? 所以我的问题是:Netbeans可以报告PHP异常吗?


Regards to @Andy's solution 关于@Andy的解决方案

I prepare this code for testing: 我准备以下代码进行测试:

<?php

function exceptionHandler($ex) {
    echo 'Uncaught exception: ', $ex->getMessage(), "\n"; // 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. Netbeans停止并报告我的断点,因此解决了一个问题。 But NB immadietly show alert titled "Socket Exception" with text: 但是NB会用文本显示标题为“ Socket Exception”的警报:

Socket Exception occured 发生套接字异常

If you have ane Watches, try to remove them and restart debugger. 如果您有ane Watches,请尝试将其删除并重新启动调试器。 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. 请附加IDE日志。 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. 我认为PHP会在发生异常时终止,因此xdebug必须停止并且Netbeans会丢失调试数据。

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中启动“调试”模式时,如果未处理的异常通过,则该异常会输出到您的浏览器,就像您没有运行调试器一样。

Netbeans doesn't magically catch them. Netbeans不会神奇地抓住它们。 ie 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. “ netbeans-xdebug”仍在“运行”中,因为它实际上仍在运行,并且将继续运行,直到您自己停止它或调试会话发生严重错误,这可能与php无关。 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. 如果您自己停止它,则netbeans将在浏览器中创建一个新选项卡,表明xdebug会话已结束。

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. 如果在浏览器中单击“刷新”,则netbeans将捕获该请求并对其进行分析,如果已设置断点,它将在该断点处停止。 After that request has been serviced, if you hit refresh again, netbeans will keep catching any requests that come in. 处理完该请求后,如果再次单击刷新,netbeans将继续捕获传入的任何请求。

Edit : One thing I found on the xdebug site that might help you in a way with exceptions in the following option. 编辑:我在xdebug站点上发现的一件事可能会在以下选项中提供一些例外帮助。

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. 您可以在xdebug部分的php.ini文件中设置此选项。

One workaround for this situation is to use the set_error_handler() function to set a custom error handler, and then set a breakpoint inside that custom error handler. 一种针对这种情况的解决方法是使用set_error_handler()函数设置自定义错误处理程序,然后在该自定义错误处理程序中设置一个断点。 When an error occurs, netbeans will stop at your breakpoint and you'll have full access to the Call Stack where you can look at any variables at the time of the error. 发生错误时,netbeans将在您的断点处停止,您将拥有对调用堆栈的完全访问权限,您可以在其中查看发生错误时的任何变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM