Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

On the other hand, if I have a NameError:

nonExistingFunction()

It does break, allowing me to easily see where it wrong... It can break the code apparently

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

My settings for debugging, if that helps My settings for python tools > debugging

like image 520
user886079 Avatar asked Jan 18 '26 04:01

user886079


1 Answers

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.

enter image description here

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:

enter image description here

like image 58
HelloWorld Avatar answered Jan 20 '26 20:01

HelloWorld