Debugger breaking on handled exceptions

Jan 18, 2013 at 5:31 PM

Hello,

I have a Python project which has various statements like this:

try:
    import readline
except:
    pass

When debugging with Python Tools for VS, the debugger breaks at that import line because "No module named readline."

If I continue, program execution proceeds fine, but every time that "import readline" call throws an error, the debugger breaks. It is quite frustrating.

This problem is isolated to one Python project. I don't experience this behavior in other projects.

Has anyone experienced this? Does anyone know what I can do to fix this?

Thanks!

Coordinator
Jan 18, 2013 at 5:46 PM

First you should check your exception settings for that project. These can be found under the "Debug" menu and "Exceptions..." - see if ImportError has both columns selected. We do normally detect the try/except correctly and won't break unless the "Thrown" column is selected. To prevent breaking entirely, you can deselect both columns, though this does mean that any ImportError will simply bring down the entire process rather than breaking into the debugger.

It is also possible that a parser error is preventing us from properly detecting the handlers in this file. Are you able to link us to the source (or email it to ptvshelp@microsoft.com)? If there is something causing an error then we'd like to fix it, but without the entire file there's no way for us to know what is causing it. (The whole project is probably unnecessary - exception handlers are managed on a per-file basis.)

Jan 18, 2013 at 5:57 PM
Edited Jan 18, 2013 at 5:59 PM

First of all, if I go into Debug > Exceptions, I see that Thrown is not checked for ImportError. I don't see the other column: http://screencast.com/t/NqrtHvbyoc48

Second, the places where the debugger is breaking are in third-party imported modules. One of these modules is cx_ReadLine, which you can access here: https://bitbucket.org/anthony_tuininga/cx_pygenlib/src/f4fb767df378/cx_ReadLine.py#cl-108. The "import readline" statement at line 108 is where I am having trouble.

So, I'm not experiencing the problem with the debugger in my own files in the project. I'm only experiencing it with imported modules.

FYI - I am using the latest version of Python Tools for VS on Visual Studio 2012 Update 1

Coordinator
Jan 18, 2013 at 6:30 PM

How are the modules linked into your project? Are they picked up from site-packages or in a search path?

You can enable the second column by turning on "Just My Code" from Debug->Options. Unchecking "User-unhandled" should get you up and running again.