【问题标题】:PHP Debug in Visual Studio Code breaks on every exceptionVisual Studio Code 中的 PHP 调试在每次异常时都会中断
【发布时间】:2017-11-16 05:10:09
【问题描述】:

我刚刚开始在 Visual Studio Code (Ubuntu 14.04) 中使用 PHP Debug 扩展。它对我来说大部分都很好,但是我有一个问题,每次抛出异常时,调试器都会自动中断。我们有很多异常在我们的代码中被内部捕获和处理,所以我不想单步执行这些异常。

我一直试图在 Visual Studio 2015 中找到类似 Exception Settings 的内容,但在 Visual Studio 代码中找不到任何等效选项。

php.ini 设置:

[debug]
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

Visual Studio 代码启动.json:

{
   "version": "0.2.0",
   "configurations": [      
       {
           "name": "Launch currently open script",
           "type": "php",
           "request": "launch",
           "program": "${file}",
           "cwd": "${fileDirname}",
           "port": 9000,
           "args": ["some arguments"]
       }
   ]
}

请注意,当我使用 Netbeans 使用相同的 xdebug 设置和相同的代码库进行调试时,不会出现异常中断行为,因此我认为这一定是 Visual Studio Code 和/或 PHP 调试扩展中的内容。

谁能建议如何在不中断的情况下通过异常?

【问题讨论】:

    标签: php debugging exception visual-studio-code xdebug


    【解决方案1】:

    我自己刚刚找到了答案(现在感觉有点傻!)。

    在 Visual Studio Code 中,转到 View->Debug,然后取消选中 Breakpoints 部分中的“Everything”按钮。该选项将自动中断 PHP 通知、警告和异常。

    【讨论】:

    • +1 如果它让你感觉不那么 s*,我也觉得 s*...我不得不省略 s* 这个词,因为 Stack Overflow 认为我的评论没有建设性。
    • 你应该接受你自己的答案!我现在因为没有看到这些选项而感到愚蠢! ;-)
    • 哇!我也想念他们!感谢您留下这个答案。
    • 我爱你们所有人,谢谢你们,对不起,我们都是这样的笨蛋,哈哈
    • 对于奖励积分,我已经在我正在使用的库上留下了一个详细而令人尴尬的 GitHub 问题!我赢得了doofus奥运会吗?
    【解决方案2】:

    然后按照下图的这些步骤进行操作

    勾选和取消勾选你想要的

    【讨论】:

      【解决方案3】:

      我正在寻找这个问题的另一个答案

      我的 Composer 依赖项中有断点,这让调试变得非常烦人。

      对于遇到相同问题的任何人,您可以在launch.json 文件中设置属性ignore,并使用一组全局模式供PHP 调试扩展忽略。

      {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
          {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "ignore": [
              "**/vendor/**/*"
            ]
          },
          {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000,
            "ignore": [
              "**/vendor/**/*"
            ]
          }
        ]
      }
      

      【讨论】:

      • 这正是我想要的。一种告诉 Xdebug 忽略某些目录中的异常的方法。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 2020-01-01
      相关资源
      最近更新 更多