简体   繁体   中英

Python (visual studio) break on error

I have Visual Studio 2015 with Python Tools, and I'm trying to debug a python application, but it doesn't break on a certain error.

The error is an IndexError, which can be reproduced with this code:

matrix = [5, 6, 7]
print matrix[2]
print matrix[5000]

Running this will gives me a message in the console, but it won't automatically break. 控制台消息

On the other hand, if I have a NameError:

nonExistingFunction()

It does break, allowing me to easily see where it wrong... 它显然可以破坏代码

Is this normal? And is there a way to make visual studio break when there's an error like that IndexError?

Here is a screenshot of the options window (no idea if this actually applies to python) and the python tools > debugging

我的调试设置(如果有帮助) 我的python工具设置>调试

Take a look at the documentation of PVTS in the category exceptions .

If an error occurs while your program is being debugged, and you don't have an exception handler for it, the debugger will break and show you the error.

在此处输入图片说明

A section later they say:

If you are being interrupted often by the debugger breaking on exceptions, or if the debugger is not breaking on some exceptions that you would like it to break on, you can modify the settings in the Exceptions window. On the Debug menu, click Exceptions, and expand the Python Exceptions entry. Here you can see all the exceptions that are already know and can be configured.

For Visual Studio 2017,

The Debug > Windows > Exception Settings menu command brings up a window in which you can expand Python Exceptions:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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