Visual Studio:调试时如何忽略已知异常?

时间:2019-05-30 14:24:39

标签: django visual-studio

我正在使用Visual Studio代码版本1.34进行调试。

由于非关键异常,我设置了一个未达到的断点。

如何停止这种行为?我正在处理配置文件,以便在VSC中使用Django进行调试。

launch.json

{
    // 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": [
        {
            "type": "extensionHost",
            "request": "launch",
            "name": "Launch Extension",
            "runtimeExecutable": "${execPath}",
            "args": [
                "--extensionDevelopmentPath=${workspaceFolder}"
            ],
            "outFiles": [
                "${workspaceFolder}/out/**/*.js"
            ],
            "preLaunchTask": "npm"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}\\manage.py",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

在python中,您可以使用 try except

如果您知道正在引发的异常:

try:
    with open('file.txt') as file:
        read_data = file.read()
except FileNotFoundError as fnf_error:
    print(fnf_error)

print('this will still be executed')

如果您不知道抛出什么类型的异常:

try:
    function_that_throws()
except:
    print('caught exception')

print('this is still executed')