Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 7 Xdebug in VSCODE: how to ignore exceptions

Tags:

I'm using plugin PHP Debugger in Visual Studio Code to debug PHP codes. All were ok with PHP <= 5.6. The debugger worked like a charm. But when I try to debug the code with PHP 7, it does not work as expected. It does not jump to the break points I added, I was stuck at thounsand excepton like

Exception has occurred. Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; RecurringType has a deprecated constructor

Or

Exception has occurred. Warning: Declaration of AntlrLexer::matchAny() should be compatible with BaseRecognizer::matchAny($input)

Or

Exception has occurred. Notice: Trying to get property of non-object

These exception are generated by the Framework so I can not fix them all, I just want to skip all these exceptions and jump to my break points only.

How can I achieve that? Thanks.

like image 440
Hieu Nguyen Avatar asked Aug 09 '18 03:08

Hieu Nguyen


People also ask

How do I break all exceptions in Visual Studio?

Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.


2 Answers

I don't know if this will work with your configuration (I'm using PHP 7.2 with WordPress), and have found this works to keep XDebug from triggering every Exception, Warning, Notice, etc. if I just want to step through my own sections of code.

First, uncheck everything (including Everything, if checked) in the Breakpoints debug section:

XDebug Breakpoints

Then hover over the Breakpoints bar and click the +:

Breakpoint bar - Add Function

Now add the name of a function you want to debug:

Add breakpoint function

Finally, set a breakpoint within that function. You will now be able to trigger an XDebug step-through only within that function:

Stepping through an XDebug session without triggering every exception

You can, presumably, add as many of your own function breakpoints as you want. An interesting aside is that if you have multiple functions with the same name, you only have to add the function name once.

like image 112
MQuiggGeorgia Avatar answered Oct 10 '22 03:10

MQuiggGeorgia


In my case the extension or editor came with the EVERYTHING option checked by default. Unchecking EVERYTHING checkbox fixed the issue.

like image 40
Rafalfaro Avatar answered Oct 10 '22 04:10

Rafalfaro