Wish debugger to show variables as set immediately before Exception

When PyCharm runs a python script and an exception is present it shows a stack trace in the console, but no variables are present in the variables window.

I'm wondering if when a fatal exception occurs PyCharm could provide me more insight into what was happening at the time. I think this should be possible from my experience with other IDEs. And, although my memory may be playing tricks on me, I thought this had been the case in PyCharm.

If there are any settings changes I could make to enable this feature I'd greatly appreciate any advice that anyone can provide.


Have you tried using Debug functionality of PyCharm? If you just run Debug without any breakpoints, and it will reach the exception, it will show the variables with their values in a separate tab.


Thanks for your response Andrey. Since posting I've noticed that sometimes it does in fact work as you describe, but there are plenty of time when it doesn't merely ending with console output and so far I can't work out which exceptions cause this. I'll post the next example I see.

Hi Nick, If you want to analyze the variables up until a certain point in your program, you can place some breakpoints, then PyCharm should display the variables state at each breakpoint, and it should do that every time.

Thanks but I want to debug at the point an exception occurs whenever that may be. It won’t be every time execution passes over a breakpoint.


I see that the last entry was a while ago, but I just ended up here looking for a solution to the same problem:

A breakpoint is passed hundreds or even thousands of times without error, but at the "Thousand and Xth time" an exception is thrown - and what exactly the values of all variables were in the step before, I can't see in the variable field. To see this, I have to click through the said hundreds of thousands of times from the set breakpoint in round n to the set breakpoint in round n+1 and so on. I have to look at the variables or remember a counter each time - because I never know whether the exception will occur with the next click and I won't see the variable again.

Now I have found a good hint at StackOverflow and would like to document briefly what I did, after this help, to solve my problem, in case someone else drops in here at a later point in time, looking for a solution, too:


There is a setting to fix this ridiculous behavior of the debugger. I'm not sure how it's turned off by default, but here we are.

  • Run > View Breakpoints
  • Check “Python Exception Breakpoint” on the left
  • Also check the child option “Any exception”

It should now behave like every debugger should, by default, in any language, on any platform, since the invention of debuggers.



Please sign in to leave a comment.