Confused about exceptions during debugging

Answered

When an unhandled exception occurs during debugging, I'm finding it really hard to see what the exception is, at the point it occurs. It seems I can only see the exception message if I let the program run to completion and then look for the exception message in the console window.

Two simple scenarios:

1. I have a a few lines of code that I am going to debug and one of them causes an unhandled exception. If I debug this program with no breakpoints enabled (but I do have the Exception breakpoint turned on for "All exceptions") the debugger will stop on the offending line of code, but the only message in the console is "Breakpoint reached: all exceptions".. how am I supposed to know what the exception is at this point?

2. If I single step through the same few lines of code and I get to the offending line of code and execute it, I see "Breakpoint reached: all exceptions".. but again, no details.

Is there a setting I don't have turned out that can tell me the exception message when it occurs instead of waiting until the program has ended?

In both cases, when I try single stepping after the offending line of code, each single step takes me to the previous location in the call stack, until I eventually wind my way out of the program. This makes sense, but if you are not "expecting" an exception and you are just single stepping your way through code and all of a sudden you are not on the next line of code, but have been popped back in the call stack, it's very confusing

It would be great for pycharm to stop at the point the exception is raised and tell you any exception details it has, let you examine your frame, and then the next single step should take you back in the call stack.

Any input on any of the above would be great!

Thanks

Michael

5
6 comments

Took me a while to find this page, but I'm glad it's not just me who's amazed at the inability to see any exception details when the IDE breaks on an exception.

1

Hi Mal! Since 2011 many things changed: when debugger breaks at Exception breakpoint, you can see a stack frame (like for every other breakpoint), you can see exception object's fields (variable '__exception__' in the Variables Pane).
Which other details do you want to know? 

0

Ah... it was the "variable '__exception__' in the Variables Pane" bit that I was missing. Thanks.

0

I don't have `__exception__` in my Variables pane, and it shows as None if I add it, even when I raise a ValueError and step through. I'm using Pytest with Pycharm version 2019.2.3.

0

Update: It's not Pytest, it happens in the most vanilla of classes. If I catch with `except Exception as e`, I can see the type and args of "e" in the Variables tab, but I don't see an __exception__.

0

OK, my vanilla project started working (breaks on the exception with a red lightning bolt in the gutter and __exception__ in Variables). This happened after I inserted this traceback code into my file. The weird thing is it kept working after I removed that code!

In my main project, inserting that code didn't help, but I got the desired behavior by turning on "Any Exception", "On Raise", "Ignore Library Files" in View Breakpoints (Ctrl+Shift+F8). My vanilla project works without that turned on, but my Pytest project needs it and stops showing the exception if I turn it off.

1

Please sign in to leave a comment.