1

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(), "\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. 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 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

9 Comments

What a pity I couldnt serious debug my php... Thanks
What do you mean? XDebug is a pretty awesome tool considering it's free and it prints out a detailed stack trace when an exception happens. What kind of tools are you used to? I mean, once PHP, or most languages for that matter, hit an exception they just go up the stack. If your code catches the exception the you can keep debugging but otherwise the program stops executing.
I want to catch uncatched exceptions from netbeans or any simple xdebug client, not from browser, because I'm using php to generate json responses for ajax requests frequently and then exceptions printed in content is not a good solution.
xdebug is for debugging though. it shouldn't be used in a production system. You should be handling those exceptions somehow and passing an adequate response back in your json so the client knows the call failed.
I think I understand a little better now. You don't want the exceptions in your json. They might be exceptions you haven't prepared for yet or haven't seen. I say put a try catch around it and if you come across any unexpected exceptions then log it with log_error() and then send a 'failed' response to the client. That way you have an entry in the log file that can help you debug and your client doesn't get bad output.
|
2

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

2 Comments

I must test this workaround to accept, but I can't do it now. I want test it in this week. Thanks for promising solution.
Generally it's work - stops Netbeans to listening xdebug. But NB loses debugging data. Look at my edit. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.